In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to understand java's integer cache". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand java's integer cache".
First of all, we all know that integer is cached in the range of-128to127. the cache is designed to save memory and improve performance.
Guess, is there a similar cache design for Long? Public static void main (String [] args) {Integer integer1 = 3; Integer integer2 = 3; System.out.printf ("integer1 = = integer2: [% s]\ n", integer1 = = integer2); Integer integer3 = 300; Integer integer4 = 300; System.out.printf ("integer3 = = integer4 result: [% s]\ n", integer3 = = integer4); System.out.println ("- wrap -") Long long1 = 3L; Long long2 = 3L; System.out.printf ("long1 = = long2: result: [% s]\ n", long1 = = long2); Long long3 = 300L; Long long4 = 300L; System.out.printf ("long3 = = long4: result: [% s]\ n", long3 = = long4);}
The returned values are as follows:
Integer1 = = integer2: [true] integer3 = = integer4 result: [false]-Line feeds-long1 = = long2: result: [true] long3 = = long4: result: [false] dissect integer
There is a private static class IntegerCache static inner class in the java.lang.integer class. The javadoc is as follows:
/ * * Cache to support the object identity semantics of autoboxing for values between *-128and 127( inclusive) as required by JLS. * * The cache is initialized on first usage. The size of the cache * may be controlled by the {@ code-XX:AutoBoxCacheMax=} option. * During VM initialization, java.lang.Integer.IntegerCache.high property * may be set and saved in the private system properties in the * sun.misc.VM class. , /
The maximum value (high) can be specified by the-XX:AutoBoxCacheMax= attribute, but there is a judgment in the code to ensure that it is not less than 127s.
Dissecting Long
There is a private static class LongCache static inner class in the java.lang.Long class. The code is as follows:
Private static class LongCache {private LongCache () {} static final Long cache [] = new Long [- (- 128) + 127 + 1]; static {for (int I = 0; I < cache.length; I +) cache [I] = new Long (I-128) }} Thank you for your reading. The above is the content of "how to understand java's integer cache". After the study of this article, I believe you have a deeper understanding of how to understand java's integer cache, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.