I have this method stub:
public <T extends Things> T createInstance(Class<T> clazz) {
return null;
}
How can I create a Things
object without reflection?
I have this method stub:
public <T extends Things> T createInstance(Class<T> clazz) {
return null;
}
How can I create a Things
object without reflection?
You can't. Just by having Class<T>
you are already using reflection.
In Java class T can come from a library that is compiled separately (sooner or later) from your code. This means that a runtime representation of the class must be used to create the instance.
As far as I understand, C++ does allow a non-reflective instantiation, but you need to recompile your code using header files for the external library to make it work, and therefore make your code dependent on the library in question.