Comparing reference equality for Integer objects in Java is a bit of a
minefield...
Integer x = 1;
Integer y = 1;
System.out.println("1==1? " + (x==y ? "yes" : "no"));
x = 127;
y = 127;
System.out.println("127==127? " + (x==y ? "yes" : "no"));
x = 128;
y = 128;
System.out.println("128==128? " + (x==y ? "yes" : "no"));
the above code produces:
1==1? yes
127==127? yes
128==128? no
because Java interns integers from -127 to 127.
On Thu, Sep 23, 2010 at 4:36 PM, Scott Blum <[email protected]> wrote:
> This actually gives me pause. What kind of code can leave primitives on
> one side but not the other?
>
> I'm concerned because in Java, I think this should be true:
>
> Integer.valueOf(1) == 1
>
> Because the RHS gets autoboxed. If we're translating this as-is into JS
> triple-equals without boxing it, the test would fail.
>
> --
> http://groups.google.com/group/Google-Web-Toolkit-Contributors
>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors