Say I have a class like this:
class ParameterizedType<T>{
public boolean equals(Object o){
if (ParameterizedType<T>.class.isInstance(o)){
ParameterizedType<T> other = (ParameterizedType<T>) o;
return this.toString() == other.toString();
}
return false;
}
}
I can get two different warnings from eclipse in such a method.
ParameterizedType<T>.classis not syntactically correct(ParameterizedType<T>)o is an unchecked cast
How could one get around this?
@SuppressWarnings("unchecked"). Eclipse gives helpful hints when you hover over the warning. By putting this in you are telling yourself, and other developers, that yes I acknowledge that this is unchecked but I need to do it.equalsby referring to thetoStringmethod anyway, but comparing strings with==is a serious mistake.