Integeter127 and 128

Source: Internet
Author: User

1  PackageCom.hangao.basic;2 3 /**4  * @authorHangao [email protected]5  *6  */7  Public classTestint {8      Public Static voidMain (string[] args) {9Integer Ie1 = 127;TenInteger Ie2 = 127; OneSystem.out.println ("Integer 127==127:" + (Ie1 = = ie2));//Integer 127==127:true A          -Integer ie3 =NewInteger (127); -Integer ie4 =NewInteger (127); theSystem.out.println ("New Integer 127==127:" + (ie3 = = ie4));//New Integer 127==127:false -          -Integer IE5 = 128; -Integer IE6 = 128; +System.out.println ("Integer 128==128:" + (IE5 = = IE6));//Integer 128==128:false -          +Integer IE7 =NewInteger (128); AInteger IE8 =NewInteger (128); atSystem.out.println ("New Integer 128==128:" + (IE7 = = IE8));//New Integer 128==128:false -          - Analysis (); -     } -  -     Private Static voidAnalysis () { inInteger IE0 = 127; - System.out.println (IE0); to         /*L0 + linenumber 5 L0 - Bipush 127 the invokestatic java/lang/integer.valueof (I) Ljava/lang/integer; * ASTORE 1*/ $         /*from the bytecode file you can see that there is an auto-boxing action*/Panax Notoginseng          -         /*Public static Integer valueOf (int i) { the if (i >= integercache.low && i <= integercache.high) + return integercache.cache[i + (-integercache.low)]; A return new Integer (i); the         }*/ +         /*The boxing process of the Integeter class can be seen in the int value between (-128-127) from the Integeter source code. - it actually returns the object inside the Integercache cache[] array.*/ $          $         /*private Static class Integercache { - static final int low = -128; - static final int high; the static final Integer cache[]; - Wuyi Static { the //High value is configured by property - int h = 127; Wu String integercachehighpropvalue = - sun.misc.VM.getSavedProperty ("Java.lang.Integer.IntegerCache.high"); About if (integercachehighpropvalue! = null) { $ try { - int i = Integer.parseint (integercachehighpropvalue); - i = Math.max (i, 127); - //Maximum array size is Integer.max_value A h = math.min (i, Integer.max_value-(-low)-1); + } catch (NumberFormatException nfe) { the //If The property cannot is parsed into an int, ignore it. -                     } $                 } the High = h; the  the cache = new integer[(high-low) + 1]; the int j = Low; - for (int k = 0; k < cache.length; k++) in Cache[k] = new Integer (j + +); the  the //Range [ -128, 127] must be interned (JLS7 5.1.7) About assert Integercache.high >= 127; the             } the  the Private Integercache () {} +         }*/ -         /*Integercache is an integer inner class that initializes an array of integer classes that correspond to all int values created (-128-127) when loaded by the JDK . the you can take it from the inside when you use it.*/Bayi     } the}

Integeter127 and 128

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.