I have a class with a type
public class Scan<T extends Data>{
...
}
Data is a abstract type, from which I have some Implementations.
Now I want some kind of chooser, which implementation to use. Is this possible? If yes, which type must the variable have (I tried with Class, but this does not work)
Class datatype;
switch(datatypeInt){
case 2:
datatype = Simple3DData.class;
break;
case 1:
default:
datatype = Simple2DData.class;
}
Scan<datatype> scan = new Scan<>();
(Obvious this does not work)
I can't instantiate Scan in the switch block, because I will also choose the Scan class at some point dynamically.
EDIT:
I see, this is not possible that easy, I will try convert the code, not to use types, rather replacing all my T by Data and passing the Class object as parameter for my Scan.
Scan<datatype>if you don't know whatdatatypeis at compile time? That is, how would the rest of your code go?Scan<? extends Data>?Simple3DDataandSimple2DData?