Sorry Aussie, but I feel a need to nitpick here to set the record straight.
1) They're called
primitives. That includes the primitive numeric types and boolean.
2) Overriding equals(...) to return true for equivalent object states is orthogonal to implementing Comparable, granted that a class that implements Comparable must always override equals(...) for consistency, unless the implementation of Comparable has to fulfill some extremely rare (aka wierd
) requirement.
The reverse, as implied in your statement, is
not true. Comparing String or any other objects for equality of state using equals(...) does not in any way depend on the class implementing Comparable.
3) More strictly, it checks the
equality of the
references. Two references (aka reference variables) are equal if both refer to the same object. (Two primitive variables are equal if they contain the same value, but everyone knows
that )
4) Very useful especially in event driven programming where the event holds a reference to the object that created/dispatched it. For example, in a listener that's added to several GUI components to perform the same action, but only on the component that triggered the event.
Relevant, and well explained.
db