Consider the following code:
class MyClass<T>{
public void method(){
new T();//Compile error
}
}
Does there exist a code example where type parameter can be matched to a specific type?
This error causes because at the type checked at compile time compiler doesnt match type parameter T
to a specific type. I know that we can apply reflection API to create instance of T
.