Howdy ranchers!
If the object of a wrapper is within the size of a byte and you are boxing, only one objects is made and this goes into the wrapper's pool.
The other variable refers to the same object then and so == indicates that they are the same object.
For numbers extending the range of a byte such a pooling is not possible (remember - there are a lot of different numbers out there
).
But as I said already this works only with boxing.
So:
Integer a = new Integer(10);
Integer b = new Integer(10);
System.out.println(a==b); // false
Integer c = 10;
Integer d = 10;
System.out.println(c==d); // true
Integer big1 = 1000;
Integer big2 = 1000;
System.out.println(big1==big2); // false
prints what's indicated in the comments.
== only indicates if the objects are the same, not the value.
equals indicates if they are meaningfully equal. Would be all true with the example.
Will be back in january,
Bu.