mercredi 24 novembre 2021

Java, is there a way to know if a method return type is a List

Let's say I have a class,

public class Dummy {
 public List<Integer> foo() {...}
 public Abc<Integer> bar() {...}
}

For method foo, I can check the return type using ParameterizedType. But for method bar, is there a way to know if Ab<Integer> is actually a List<Integer>?

Edit to add some background:

We have dozens of 3rd party pojo classes, we need to extract the field information of thess classes, and create a schema based on it.

For the regular primitive field, it's straight forward, but in those classes, they also have field with type like List<Integer>, or ArrayList<Integer>, or Abc<Integer> (Abc<T> may or may not implements List<T>).

So we need a way to determine if it's a repeated field or not, if it's a repeated one, what is the type argument, is it a Integer or some other things?

Many thanks.





Aucun commentaire:

Enregistrer un commentaire