Jea*_*art 3 java generics suppress-warnings
我有以下代码:
public abstract class A<T extends B<? extends A<T>>>{
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
A other = (A) obj; // warning here: "A is a raw type"
// [...]
}
}
Run Code Online (Sandbox Code Playgroud)
如何在指定的行中避免"A是原始类型"和"类型安全:未选中的强制转换"?是否存在某种类型的黑客攻击或者我的课程出错?
谢谢
如果比较的参数化类型A无关紧要,请声明并将其转换为A<?>:
A<?> other = (A<?>) obj;
Run Code Online (Sandbox Code Playgroud)
这将删除警告.