mardi 27 octobre 2015

How can i get Class from Generic Type

I do not know how I will explain, I have a class something like

public class MyClass<T>{
    private Class <?> type;
    public MyClass(string className){
        this.type = Class.forName(className);
        Field[] fields = type.getDeclaredFields();//why i need type
    }
}

Then i create an object of that class:

MyClass<Person> persons = new MyClass<>("packageName.Person");

Is there anyway to do this like

MyClass<Person> persons = new MyClass<>();





Aucun commentaire:

Enregistrer un commentaire