I am getting the following code snippet from Android's Pair.java
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Pair)) return false;
final Pair<F, S> other;
try {
other = (Pair<F, S>) o;
} catch (ClassCastException e) {
return false;
}
return first.equals(other.first) && second.equals(other.second);
}
I was wondering, how is it possible to have ClassCastException, after instanceof
returns true.
It isn't possible. The code makes no sense. Whoever wrote it probably didn't understand that F
and S
are erased at runtime so a ClassCastException
could never happen.
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