Raw Type Warning in Android Studio

二次信任 提交于 2019-12-08 18:58:17

问题


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 usually shows the following warning: GenericClass is a raw type. References to generic type GenericClass <T> should be parameterized.


回答1:


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.

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:

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



来源:https://stackoverflow.com/questions/31561804/raw-type-warning-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!