tl;dr: How do I cast an object with type parameters without incurring an 'unchecked cast' warning? i.e:
List<Foo> bar = (List<Foo>) obj;
The compiler is giving me an 'unchecked cast' warning about the following code. How do I fix the warning? Placing a @SuppressWarnings("unchecked")
before the cast would represent the saddest of solutions.
public class Container<V> {
public V getV();
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Container<V> other = (Container<V>) obj;
return this.getV().equals(other.getV());
}
}