Looking at
http://www.docjar.com/html/api/java/lang/Integer.java.html
I see this comment
If they used valueOf in parseInt , then when parseInt is called at the start of VM initialization, the high value will actually be zero.
I'm not sure what problems might arise, but apparently someone thought it was worth it to protect.
- what is the use of assert IntegerCache.high> = 127; I read that assert provides an efficient way to detect and fix programming errors. But this is runtime code, why would someone use assert?
Protection against code called during VM initialization calling the valueOf method.
- And when will an AssertionError be thrown in this scenario?
If you run java with the -ea parameter (allow statements), and there is some initialization code that calls valueOf, the JVM will crash almost immediately due to AssertionError. Hopefully the Java team will check this stuff and fix the violation code before releasing it into the wild.
Unlike other statements of the answer that the high will always be greater than or equal to 128, it seems that there are times when it is equal to zero (not counting the reflection).
emory Nov 24 '15 at 11:14 2015-11-24 11:14
source share