I want to make a generic class of this form:
class MyGenericClass {}
Problem is, I want to be acceptable for T to b
You asked for a class that accepts either of two types. That has already been answered above. However I will also answer how you can extend that idea to a method within the class you are using without need for creating another class for this. You want to use just : -
Not Double
private T doSomething(T value) throws IllegalArgumentException{
if(value instanceof Integer){
return (Integer)value;
}
else if(value instanceof Long){
return new value.longValue();
}
else
throw new IllegalArgumentException("I will not handle you lot");
}