mardi 11 août 2015

getting type of element in a List in which List is the return type of method in java

I got every methods in my package using reflections and then based on the return type of every method, I want to do some operations. But unfortunately I had a problem with collections. when I find a method in which return a collection like a List, I can't find a way to get to know about the type of List's element. I used the code below to get the return type of my methods.

if (method.getReturnType().equals(List.class)){
    statement;
}

The above code does work well and gets every method which return a List but it is just return java.util.List as a return type and I can't find a way to get to know about the type of element in that List. For instance, if I have a method like this:

public List<CmsCustomerModel> getCustomerModel(){
    statement;
}

I don't know how can I get CmsCustomerModel class as a type of element for return List. I would be wonder if anyone help me find this. Please guide me.





Aucun commentaire:

Enregistrer un commentaire