Java equal sign

Source: Internet
Author: User

From: http://www.iteye.com/topic/1116623

/* Hello. Java */
Import java. Lang. Integer;

Public class hello
{
Public static void main (string [] ARGs)
{
Int A = 1000, B = 1000;
System. Out. println (A = B );

Integer c = 1000, D = 1000;
System. Out. println (C = D );

Integer e = 100, F = 100;
System. Out. println (E = F );
}
}

 

Result:

 

True
False
True

 

Cause:

Integer type default-128 ~ 127 when cache data is used, the same object is used in the default range, so they are equal. Otherwise, they are not equal.
/**
* Returns a <tt> integer </tt> instance representing the specified
* <Tt> int </tt> value.
* If a new <tt> integer </tt> instance is not required, this method
* Shoshould generally be used in preference to the constructor
* {@ Link # INTEGER (INT)}, as this method is likely to yield
* Significantly better space and time performance by caching
* Frequently requested values.
*
* @ Param I an <code> int </code> value.
* @ Return a <tt> integer </tt> instance representing <tt> I </tt>.
* @ Since 1.5
*/
Public static integer valueof (int I ){
If (I >=- 128 & I <= integercache. High)
Return integercache. cache [I + 128];
Else
Return new INTEGER (I );
}

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.