Solution (source code)

= Solution

For primitive values, <Java> `==` compares values, subject to the primitive type's rules. For references, `==` compares <object identity>: it asks whether the references designate the same <software object>, or are both null. The `equals(Object)` <object method> permits a <software class> to define <value equality>. Its inherited `Object` implementation still uses <object identity>, so meaningful content comparison requires an appropriate override.<Java 8 Object API documentation>[equals(Object), default identity semantics and the equality contract]{ref}

For example:

``
String a = new String("wall");
String b = new String("wall");
boolean sameObject = (a == b);  // false
boolean sameText = a.equals(b); // true
``

The two allocations have different <object identities> but equal text. Using separately allocated <String data type> values avoids relying on literal interning. A `null` receiver cannot receive an `equals` call; `java.util.Objects.equals(a,b)` is a null-safe comparison. An `equals` implementation should define an <equivalence relation> and equal <software objects> must have equal `hashCode()` results.<Java 8 Object API documentation>[equals(Object) and hashCode() contracts]{ref} The distinction is
$$
\boxed{\text{reference }\texttt{==}:\text{ identity};\qquad\texttt{equals}:\text{ the class's declared equality}.}
$$