getClass() in abstract class gives Ambiguous method call

后端 未结 5 1582
北海茫月
北海茫月 2021-01-31 13:39

I have a public abstract class and I\'m trying to use the getClass() method, as I will need info from the class extending my abstract class. An example is this:

5条回答
  •  有刺的猬
    2021-01-31 14:25

    Another working workaround is to generate a helper method to get the Class:

    public Class type() {
        return super.getClass();
    }
    

    or a static reusable util:

    public static final Class type(Object object) {
        return object.getClass();
    }
    

提交回复
热议问题