getClass() in abstract class gives Ambiguous method call

后端 未结 5 1595
北海茫月
北海茫月 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:09

    This can happen if you have an Android project with Maven, and you import into IntelliJ using the Maven Android Platform as the project SDK. The problem is that both Maven Android Platform and the Android maven dependency jar includes the java.lang.Object class.

    The workaround is goint to Project structure -> Platform Settings -> SDK -> Maven Android Platform -> Classpath. It will list all the jars which are in JDK actually. Remove all of them, so only the two Android dependency remains (res and annotations.jar).

    EDIT: This problem has been already reported to IntelliJ issue tracker long time ago.

提交回复
热议问题