First of all, I know you can pass Type as a parameter by using Class<T>
.
However, I have a scenario as follows:
Suppose I have a method for creating MyOwnType (the code below compiles):
public MyOwnType<? extends Type,? extends Type> createMyOwnType(String name, Class<? extends Type> T1, Class<? extends Type> T2)
What I really want to do is to use Type variables T1 and T2 to construct MyOwnType:
MyOwnType<T1,T2>
I know you can directly construct MyOwnType without using createMyOwnType method. But I want to use a proper factory pattern to construct MyOwnType for users + a few constraints I will code up.
I don't want to check all parameters one by one say if T1 is some type, and T2 is some type, then constrcut MyOwnType. Because in some cases, I could have many Ts, they all are subtypes of Type. Therefore, I will have T1xT2xT3xT_n combinations to check.
Therefore,my question is that is there a way of creating MyOwnType based on the parameters provided (T1 and T2), something similar like the following code:
MyOwnType<T1,T2> myowntype=new MyOwnType<T1,T2>(name);
The code above won't compile due to the Java compiler cannot find symbol T1,T2.