【发布时间】:2011-06-17 07:20:45
【问题描述】:
还有其他几个 SO 问题谈论泛型编译 OK w/Eclipse 的编译器而不是 javac(即Java: Generics handled differenlty in Eclipse and javac 和 Generics compiles and runs in Eclipse, but doesn't compile in javac)——但这看起来有点不同。
我有一个enum 类:
public class LogEvent {
public enum Type {
// ... values here ...
}
...
}
我还有另一个类,它的方法接收来自Enum 的任意类型的对象:
@Override public <E extends Enum<E>> void postEvent(
Context context, E code, Object additionalData)
{
if (code instanceof LogEvent.Type)
{
LogEvent.Type scode = (LogEvent.Type)code;
...
这在 Eclipse 中运行良好,但是当我使用 ant 进行清理构建时,出现一对错误,一个在 instanceof 行,另一个在铸造行:
443: inconvertible types
[javac] found : E
[javac] required: mypackage.LogEvent.Type
[javac] if (code instanceof LogEvent.Type)
[javac] ^
445: inconvertible types
[javac] found : E
[javac] required: com.dekaresearch.tools.espdf.LogEvent.Type
[javac] LogEvent.Type scode = (LogEvent.Type)code;
[javac] ^
为什么会发生这种情况,我怎样才能解决这个问题以便正确编译?
【问题讨论】:
标签: java generics compiler-errors javac