的getClass()的抽象类给出了模糊的方法调用 [英] getClass() in abstract class gives Ambiguous method call

查看:141
本文介绍了的getClass()的抽象类给出了模糊的方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个公共抽象类,我试图使用的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.

这篇关于的getClass()的抽象类给出了模糊的方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆