I\'m trying to override equals
method for a parameterized class.
@Override
public boolean equals(Object obj) {
if (this == obj)
return t
I just ran into this problem myself, and in my -particular- case, I didn't need to know the type E.
For example:
public class Example {
E value;
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Example> other = (Example>) obj;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}
In the above code, there is no unchecked cast because of using Example>
. The type parameter wildcard '?' saves the day.