的getClass()的抽象类给出了模糊的方法调用出了、模糊、方法、抽象类

2023-09-04 08:17:03 作者:山盟海誓亦会分开 "

我有一个公共抽象类,我试图使用的getClass()的方法,因为我将需要延长我的抽象类的类信息。一个例子是这样的:

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:

public String getName() {
    return getClass().getSimpleName();
}

然而,的IntelliJ报告如下:

However, IntelliJ reports this:

Ambiguous method call. Both
getClass    ()    in Object and
getClass    ()    in Object match.

在code运行良好,但有在我的IDE几十错误警告的是有点在我的方式。它破坏我用了很多误报工作流程。

The code runs fine, but having tens of error warnings in my IDE is kinda in my way. It disrupts my work flow with a lot of false positives.

为什么显示这些错误,我能做些什么不看看呢?

Why are these errors shown, and what can I do to not see them?

推荐答案

在code是好的,但它是在的IntelliJ一个错误。

The code is fine, but it is an error in IntelliJ.

错误报告, 另一个。

有,即使这个问题有不同的变化更多一些错误报告。正如duffymo指出在评论,它也可以是因为有JDK的类路径中不同的版本。

There are even some more error reports with different variations of this issue. As duffymo pointed out in comments, it can also be because there are different versions of the JDK in the classpath.