I'm writing Java using Eclipse, and it's giving me a warning if I try to declare a Generic class without parameterising it. Thing is, I don't want to parameterise it until I instantiate it later on in the program, for example, say I have a generic class, "MyClass", which takes one parameter, and I want to do something like this:
public static void main(String args[]){
Terminal terminal = new Terminal();
MyClass myclass; //Eclipse warns me here
switch(terminal.readInt()){ //read an int from the user
case 1:
myclass = new MyClass<Integer>();
break;
case 2:
myclass = new MyClass<String>();
break;
}
}
Now this runs fine, so should I just ignore the warning or is there something I'm doing that's fundamentally wrong here?
EDIT: Ok, I realise I can write '"MyClass<?> myclass" when declaring it, and there'll be no warnings in this code, however, this seems to mean I can't pass any non-null parameters to any methods I might call on myclass later on in my program... :S