I have the following code:
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"
// [...]
}
}
How to avoid both "A is a raw type" and "Type safety: unchecked cast" at the specified line? Is there a hack of some sort or I am doing something wrong with my classes?
Thanks
If the parameterized type of the compared A doesn't matter, declare and cast it as A<?>:
A<?> other = (A<?>) obj;
This will remove the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With