Hi all, i just have a quick question about the Generic Type. i have an interface class
public interface myInterface<T> {
T add();
}
and a sub class
public class interfaceImp<T> implements myInterface
{
private T t1;
private T t2;
interfaceImp(T t1, T t2){
this.t1 = t1;
this.t2 = t2;
}
public Object add() {
throw new UnsupportedOperationException("Not supported yet.");
}
However, i have no idea about how to implement add(). Should i check the following
1. t1.getClass() == Integer.class&&t2.getClass() == Integer.class</br>
2. t1.getClass() != Integer.class&&t2.getClass() == Integer.class</br>
3. t1.getClass() == Integer.class&&t2.getClass() != Integer.class</br>
f Then case t1 or t2 to the proper type? Or there is a better way of doing it? thanks!!