Skip to content

Instantly share code, notes, and snippets.

@djeikyb
Created April 1, 2014 21:26
Show Gist options
  • Save djeikyb/9923543 to your computer and use it in GitHub Desktop.
Save djeikyb/9923543 to your computer and use it in GitHub Desktop.
public class ObjectsAndEquals
{
public static void main(String[] args)
{
Integer m0 = 127;
Integer m1 = 127;
System.out.println(m0 == m1); // true
System.out.println(m0.equals(m1)); // true
Integer n0 = 128;
Integer n1 = 128;
System.out.println(n0 == n1); // false
System.out.println(n0.equals(n1)); // true
System.out.println(n0 == 128); // true
System.out.println(128 == n0); // true
System.out.println(n0.equals(128)); // true
System.out.println((m0+1) == n1); // true
System.out.println((Integer)(m0+1) == n1); // false
}
}
@jabgibson
Copy link

Line 12 is boggling.

@jabgibson
Copy link

haha and line 20 even more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment