int i, j; i = 2; j = 2; if (i == j) { System.out.println("same"); }
This works for objects too, but not in the same way you might expect:
Ex e = new Ex(); e.field = 2; Ex f = new Ex(); f.field = 2; if (e != f) { System.out.println ("not same"); } if (e.field == f.field) { System.out.println ("same"); } e = f; // Now they refer to the same object if (e == f) { System.out.println ("same"); }