There are several other SO questions talking about generics compiling OK w/ Eclipse's compiler but not javac (i.e. Java: Generics handled differenlty in Eclipse and javac and Generics compiles and runs in Eclipse, but doesn't compile in javac) -- however this looks like a slightly different one.
I have an enum
class:
public class LogEvent {
public enum Type {
// ... values here ...
}
...
}
and I have another class with a method that takes in arbitrary objects of types descended from 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;
...
This works fine in Eclipse, but when I do a clean built with ant
, I am getting a pair of errors, one on the instanceof
line, the other on the casting line:
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] ^
Why does this happen, and how can I get around this problem so it will compile properly?