6

我从Android 的 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);
}

instanceof我想知道,在返回 true之后,怎么可能有 ClassCastException 。

4

1 回答 1

3

这是不可能的。代码没有意义。编写它的人可能不理解这一点,FS在运行时被删除,因此ClassCastException永远不会发生。

于 2012-09-25T14:36:23.847 回答