Skip to content

Object Identity vs. Object Equality

Identity –> a variable holds the SAME instance as another variable.

Equality -> two (distinct) objects can be used interchangeably. they often have the same id.

 For example

Integer a =  new Integer(1);  Integer b = new Integer(1);  a is equal but not identical to b.

Integer x = new Integer(1);  Integer y = x;  x is identical to y.

of course, two identical objects are always equal.

Leave a Reply

Your email address will not be published. Required fields are marked *