Java modifier--transient

Source: Internet
Author: User

I. BACKGROUND

Last week to develop a function of CRM, the system has automatic paging, you need to add a paging variable in the entity class

    // page out    Private New PageInfo ();

This would have had no effect, but the class used must implement the serialization interface when pulling away from the interface jar package

And this PageInfo object because in the class of extraction, so the PageInfo class must also be serialized, very uncomfortable

Because the PageInfo class is not developed by us, it is not good to modify this class to implement a serialized interface

Transient is a non-trivial modifier, and its role is reflected in the

Second, transient modifier

Transient is a keyword in the Java language that is used to indicate that a domain is not part of the serialization of that object.

When an object is serialized, the value of the transient variable is not included in the serialized representation, whereas the non-transient variable is included.

    // Paging Entities    Private transient New PageInfo ();

When you export the interface jar package, you still need to export the PageInfo class, but at least the PageInfo class does not need to implement the serialization interface.

Three, the application scenario

When a class implements a serialization interface, and a variable does not want to be serialized under a class, the variable is modified with transient to prevent the variable from being serialized

Java modifier--transient

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.