|
|
|
|
|
by kyrra
4398 days ago
|
|
It also leads to some interesting programming errors in Java. class A {
public static void main(String[] args) {
Integer a = 100, b = 100;
Integer c = 10000, d = 10000;
System.out.println(a == b);
System.out.println(c == d);
}
}
Prints: true
false
For those unaware, the == check above is doing an Object check (are they the same object). The cache makes the '100' return the same instance of an object. To do actual value checks, you'd need to do c.equals(d) |
|
At least be consistent between primitives and objectives.
Sadly, I have to use this language daily. My heart belongs to python, but java pays the bills.