How to use the "Java" class assignment

Source: Internet
Author: User

        Regioninfo regioninfo=New  Regioninfo ();        Regioninfo.setdistance (0);        Regioninfo.setinside (1);        Regioninfo.setshopid (2428069);        Regioninfo.settype (5);        Regioninfo.setrecalltype (0);        Regioninfo.setshopname ("Splash Square");        Regioninfo Regioninfo2=Regioninfo;        Regioninfo2.setdistance (1000);

The desired result is regioninfo.getdistance () = 0; Regioninfo2.getdistance () = 1000;

But the result of the operation is:

Because a reference is passed, changing a property causes two values to change, and two classes in memory are common to the same store.

If you want to copy the properties of a class directly, but there are changes, you can use: Beanutils.copyproperties (target class, source Class);

        Regioninfo regioninfo=New  Regioninfo ();        Regioninfo.setdistance (0);        Regioninfo.setinside (1);        Regioninfo.setshopid (2428069);        Regioninfo.settype (5);        Regioninfo.setrecalltype (0);        Regioninfo.setshopname ("Splash Square");        Regioninfo Regioninfo2=new  Regioninfo ();        Beanutils.copyproperties (regioninfo2,regioninfo);        Regioninfo2.setdistance (10000);

How to use the "Java" class assignment

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.