コンパイルエラー - 変換できない型。
スポンサーリンク
例えばこんなソースを Eclipse で作成してみる。
package org.aeug.rms099;
public class IncompatibleTypesError> implements Comparable {
@Override
public int compareTo(T o) {
if (o instanceof String) {
String string = (String) o;
}
return 0;
}
}
Eclipse 上では何の問題もなくコンパイルされる。
しかし javac コマンドを直接叩いてコンパイルしようとすると、「変換できない型」などというエラーメッセージが出力される。
Eclipse のコンパイラがバグってるのかどうかは分からないが、Sun のコンパイラほど厳格じゃないみたいだ。
以下、似たような問題。
- Bug 121369 – [1.5][compiler] Eclipse successfully compiles buggy code
- Bug 151966 – [compiler][batch][options] Equalize batch compiler options and JDT options represented in the GUI
- Bug 158870 – [1.5][compiler] javac inconvertible types on cast allowed by Eclipse
- Bug 164665 – [1.5][compiler] Generics supertype doesn't compile with sun - incompatible types
- Bug 174282 – [1.5][compiler] Compiler Error not shown in IDE ( cast on inherited generic class)
ちなみに「検出値」が"found"、「期待値」が"required"。
"required"=「期待値」っていう訳に微妙に違和感を覚えたのは俺だけか?