Android Studio中的原始类型警告 [英] Raw Type Warning in Android Studio

查看:290
本文介绍了Android Studio中的原始类型警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用原始类型引用泛型类型时,Android Studio不会显示编译器警告.有没有启用此功能的方法?

Android Studio doesn't show a compiler warning when using the raw type in referencing a generic type. Is there a way to enable this feature?

public class GenericClass<T> {
}

public class SpecificClass extends GenericClass {
}

Eclipse通常显示以下警告: GenericClass是原始类型.对泛型类型GenericClass< T>的引用应该参数化.

Eclipse usually shows the following warning: GenericClass is a raw type. References to generic type GenericClass <T> should be parameterized.

推荐答案

您可以启用警告,但不能将其强制为编译错误. Eclipse中也是如此[请参见尾部以获取更新].您可以参考 JLS 指出它为编译警告,而不是编译错误.

You can enable the warning but cant force it as compilation error. Same is the case in Eclipse[see tail for the update]. You can refer to JLS which states it compilation warning and not a compilation error.

您可以在android studio中启用检查.转到File > Settings > Inspection,然后打开对参数化类的原始使用"设置,如下所示可能会有所帮助:

You can enable the inspection in your android studio. Go to File > Settings > Inspection and turn on the check as for the "Raw use of parameterized class" setting as shown below may help:

感谢Stephan:您可以使用以下命令在Eclipse中启用它: Java Compiler > Errors/Warnings > Generic Types > Usage of a raw type:并在组合框中选择Error

Thanks to Stephan: You can enable this in Eclipse using: Java Compiler > Errors/Warnings > Generic Types > Usage of a raw type: and select Error in the combo

这篇关于Android Studio中的原始类型警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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