Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>You can also have x != y where x and y are different objects with the same value.

May be true, but it's not guaranteed one way or the other. In the Oracle JVM the smaller integers are cached such that

  new Integer(10) == new Integer(10)
but

  new Integer(1000) != new Integer(1000)


Actually, "new Integer()" is guaranteed to always return a new, distinct object. The caching only comes into play during autoboxing conversions, or when you call Integer.valueOf().


Ah, you're right. I was thinking of autoboxing, i.e.

  Integer a;
  Integer b;

  a = 10;
  b = 10;
  a == b; // true

  a = 1000;
  b = 1000;
  a == b; // false




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: