I\'m trying to override equals
method for a parameterized class.
@Override
public boolean equals(Object obj) {
if (this == obj)
return t
You can do it by retaining a reference to Class
type. However, in my opinion, equality tests should be about the values the objects represent rather than the concrete types the values get expressed.
A classic example of this is the Collections API for example. new ArrayList
returns true
. While these have completely different types, they represent the same value, namely "an empty collection".
Personally, should two Tuple
s that represent the same data (e.g. ("a", "b")
) be not equal, because one is of type Tuple
while the other is Tuple
?