Get class of generic

前端 未结 5 1014
野趣味
野趣味 2020-12-16 05:22

My class starts with

public abstract class LastActionHero(){

Now somewhere in the code I want to write H.class<

5条回答
  •  忘掉有多难
    2020-12-16 05:33

    One way is to keep reference to your parameterized type like having an attribute of

    private Class clazz;
    

    And create a setter or a constructor that takes in a Class.

    Parameterized Types are erased at runtime, hence why you can't do what you ask.

提交回复
热议问题