- 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 = a;
a
is identical to b
.Integer c = new Integer(1);
Integer d = new Integer(1);
c
is equal but not identical to d
.
Of course, two identical variables are always equal.
No comments:
Post a Comment