vendredi 25 octobre 2019

How do I get the generic type of a list at runtime in java?

Is there a way to get the returned Generic type of a List at runtime using reflection / java 8 ?

In the following example, I want to get the type Student.

class MyClass{

    public List<Student> getStudent(){
        // ...
    }
}

Please note that the returned list at runtime may be empty, so please don't suggest me to check the type of the first element.





Aucun commentaire:

Enregistrer un commentaire