I\'m trying to override equals method for a parameterized class.
@Override
public boolean equals(Object obj) {
if (this == obj)
return t
Since generics are erased at compile time, you basically can't. At runtime, any type parameter is gone, and as far as the JVM is concerned, they are exactly the same in all respects.
The way to work around that is to store a Class field that represents the type, and create the object with that type in the constructor.
A sample constructor:
public class Tuple < E > {
public Tuple(Class c) {
//store the class
}
}
Or you could use a factory:
public static Tuple getTuple(Class type) {
// Create and return the tuple,
// just store that type variable in it
// for future use in equals.
}