Get type of a generic parameter in Java with reflection

后端 未结 18 2166
死守一世寂寞
死守一世寂寞 2020-11-22 05:56

Is it possible to get the type of a generic parameter?

An example:

public final class Voodoo {
    public static void chill(List aListWithTy         


        
18条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 06:31

    This is impossible because generics in Java are only considered at compile time. Thus, the Java generics are just some kind of pre-processor. However you can get the actual class of the members of the list.

提交回复
热议问题