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);
}

instanceoftrueを返した後、ClassCastExceptionを発生させるにはどうすればよいのでしょうか。

4

1 に答える 1

3

それは不可能です。コードは意味がありません。それを書いた人はおそらくそれを理解しておらずFS実行時に消去されるので、ClassCastException決して起こり得ませんでした。

于 2012-09-25T14:36:23.847 に答える