I would like to make a method, that would make instance of my generic class. The type of this object have to be specified by given String. Prototype looks like this:
public class SomeClass {
static BST<?> bst;
public static void main(String[] args)
{
MakeInstance("String");
}
static <T extends Comparable<T>> void MakeInstance(String input)
{
try {
bst = (BST<?>) Class.forName(input).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}
I would like to type for example "Integer" and method should create object of BST of type Integer (BST)