Android Studio - 不明确的方法调用 getClass() [英] Android Studio - Ambiguous method call getClass()

查看:34
本文介绍了Android Studio - 不明确的方法调用 getClass()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Android 应用程序使用的是 Android Studio.
我的代码可以运行并编译.
最近,IDE 在以下代码的 getClass 上显示错误(红线):

I'm using Android Studio for my Android application.
My code works and compiles.
Recently, the IDE showes me error (red lines) on getClass of the following code:

fragment.getClass().getSimpleName()

但是应用程序仍然可以编译并运行.
错误是:

But still the application compiles and runs.
The error is:

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

有人能解释一下这是什么吗?为什么代码还在运行?

Can some one explain me what is it about? and why the code still running?

推荐答案

我认为这是 Android Studio 中的一个错误.众所周知,Android Studio 基于 IntelliJ 平台和 IntelliJ IDEA 社区版的现有功能.

I think it is a bug in Android Studio. As we know, Android Studio is based on the IntelliJ Platform and the existing functionality of IntelliJ IDEA Community Edition.

Google 与 JetBrains 合作开发了它.据报道,IntelliJ 中也发生了同样的错误.查看错误报告

Google has developed it in cooperation with JetBrains. And same bug is reported to happen in IntelliJ as well. Have a look at the Error report

解决此问题的唯一解决方法是将您调用 getClass() 的实例强制转换为 Object,如下所示:

The only workaround to this issue is to cast the instance you call getClass() on, to Object as follows:

((Object) this).getClass()

这篇关于Android Studio - 不明确的方法调用 getClass()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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