怎么可能有ClassCastException异常的instanceof返回true后 [英] How is it possible to have ClassCastException after instanceof returns true
本文介绍了怎么可能有ClassCastException异常的instanceof返回true后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从以下code段<一个href=\"http://$c$c.ohloh.net/file?fid=-0F0FCOc_Dgka3ovb86Swu0zffI&cid=OpnM-8VCwHE&s=Pair.java%20Android&browser=Default#L44\"相对=nofollow> Android的Pair.java
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);
}
我想知道,怎么可能有ClassCastException异常,后的instanceof
返回true。
推荐答案
这是不可能的。在code是没有意义的。谁写它可能不明白,˚F
和取值
在运行时都被擦除,一个 ClassCastException异常
可能永远不会发生。
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.
这篇关于怎么可能有ClassCastException异常的instanceof返回true后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文