Get generic type of java.util.List

后端 未结 14 2665
广开言路
广开言路 2020-11-22 02:06

I have;

List stringList = new ArrayList();
List integerList = new ArrayList();

Is

14条回答
  •  面向向阳花
    2020-11-22 02:24

    Generally impossible, because List and List share the same runtime class.

    You might be able to reflect on the declared type of the field holding the list, though (if the declared type does not itself refer to a type parameter whose value you don't know).

提交回复
热议问题