When looking at the source code for Integer.parseInt(String s, int radix) (java 8, 1.8.0_131), I found the following block of comments:
While I understand the first part of IntegerCache, I donβt understand why there is a warning about valueOf and why in this context.
I see that valueOf() relies on parseInt() , but I still don't understand why this warning.
Can someone explain what exactly the comment warns me (and the context where valueOf should not be used), and what could go wrong.
Edit:
The code in Integer.valueOf (int i) seems to have changed since another question was asked from the comment below, now it
public static Integer valueOf(int i) { if (i >= IntegerCache.low && i <= IntegerCache.high) return IntegerCache.cache[i + (-IntegerCache.low)]; return new Integer(i); }
and must be saved earlier.
java
Michael Jun 19 '17 at 17:40 2017-06-19 17:40
source share