Here's the code:
package Fabrika.Trake;
import Vozila.*;
public class Traka<T extends Vozilo> extends Thread
{
protected int vrijemeRada;
...
@Override
public void run()
{
while(true)
{
//I want to create the object here
}
}
}
Now, let's say I have a class called Auto which extends Vozilo.
I'd like to know if there is a way of constructing an object of type T without using reflection. Something like:
T object = new T();
This, of course, is completely incorrect, but it just serves as an illustration of what I'd like to do. :)
You can't do this with just the generic type
T
.To create an instance you need a
Class
instance.E.g.:
Usage:
The problem is that the generic type information
T
is erased at runtime. Therefore you need aClass
instance to represent the type at runtime.