In OpenJDK, for the method:
public static Double valueOf(double d)
The javadoc says:
Returns a Double instance representing the specified double value. If a new Double instance is not required, this method should generally be used in preference to the constructor Double(double), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
Here's the actual code:
public static Double valueOf(double d) {
return new Double(d);
}
The cache is a lie! What's going on here?