For example, if I am implementing my own Collection<E> that uses a Hashtable<E, Integer.> as its underlying data structure, I will implement remove(Object o), but o is not an E, it's an Object. But, if it returns true for containsKey(o), then am I safe to assume that casting o to E is going to succeed?
@Override
public boolean remove (@NotNull final Object o)
{
if(underlyingHashTable.containsKey(o))
{
@NotNull final E item = (E) o;
}
}
The IDE highlights the cast to (E) o as unchecked but I'm wondering if my assumption is sane & safe.