dimanche 30 juillet 2017

Is it possible to create an instance of parameterized class in Java?

I have the same logic in classes creation, but actual classes are different. Is it possible somehow to create an instance of a parameterized class?

Here is an example:

public class MyClass <E extends MyEntityClass> {
    public List<E> myList = new LinkedList<>();

    public MyClass(JsonArray params) {
        for(JsonElement param : params){
            myList.add(new E(param));
        }
    }
}

MyEntityClass - is the super class which has the constructor which accepts JsonElement.

I know that Java doesn't allow to create the parameterized class, but is it possible to solve somehow this problem?





Aucun commentaire:

Enregistrer un commentaire