Get type of a generic parameter in Java with reflection

后端 未结 18 1956
死守一世寂寞
死守一世寂寞 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:15

    No it isn't possible.

    You can get a generic type of a field given a class is the only exception to that rule and even that's a bit of a hack.

    See Knowing type of generic in Java for an example of that.

提交回复
热议问题