I was wondering if it is possible to declare a new object of a specific type in Java, given that I have this type represented as an object of a class.
For example, let's say that I have
SomeClass obj1;
Class c = obj1.getClass();
Now I would like to take "c" and use it to declare a new object of this type. Something like that:
Class<c> my_new_var;
so my_new_var will then be a variable of the same type / class as obj1. This is directly related, I suppose, to whether it is possible to use a class object (or something related to this class object) as a type in the declaration of a new variable.
Is this possible or impossible, since Java is strongly typed?
Thanks in advance,
Bruno
Bruno source
share