I've come across a strange issue. I'm using Eclipse IDE with Java SE 6. When I correctly override a method from a parent class/interface and use @Override annotation, Eclipse doesn't complaint (as expected because it's a valid override). However, when I compile with ANT (version 1.7) I get the following compilation error:
This is strange. Any help shall be highly appreciated.
[EDIT] OK, that looks like one of my typical terse replies. I should add a little more info...
I use eclipse. I set the JRE to 1.6 and set the compiler compliance level to 6.0. Eclipse puts in the @Override in the class that implements the interface if I have eclipse put the method in (create the class, but no method and it complains that the class needs to implement something and I have it "add unimplemented methods"). If I change the compliance level to 5.0 it then complains about @Override. When I have eclipse add the method (5.0 still) it doesn't add the @Override.
(Maybe it was better without the added explanation?)
Joined: Mar 05, 2009
Looks like it is a difference between java 5 & 6.
I tried doing the following changes and failed:
Carol, What needs to be done to get off this issue?
Joined: Oct 10, 2000
I haven't tried it out as I never use target/source with javac. Looks like 1.6 should work,possibly 6. Maybe I'll go try that.
I'd try running ant verbosely (ant -v) to see what version it is trying to use. Perhaps it is 5 and can't do 6.
[EDIT] Oh by the way, welcome to JavaRanch!!!
Joined: Mar 05, 2009
This is what I did to get out of the mess and make Ant Happy.
Ant and Eclipse are happy when: Java compiler's compliance is set to Java 6
Ant Global Entries point to Java 6 tools.jar
Ant and Eclipse are unhappy when: Java compiler's compliance is set to Java 6
Ant Global Entries point to Java 5 tools.jar
Eclipse is unhappy when Java compiler's compliance is set to Java 6 (this is strange even when it's a valid override). Can somebody explain this weird behavior.
Well, as you've seen, it's best when you keep to the same Java environment all the way through.
Your message "method does not override a method from its superclass " almost certainly comes from classloading issues. Part of Java's security model is that just because 2 classes have the exact same name and signatures doesn't mean that Java will consider them to be the same class. It's also important that they be on the same classpath branch.
As for Eclipse's problems, the first thing you need to do is ensure that you've installed the desired JDK into Eclipse and that the project in question is going to refer to it, either because it's the default workspace JRE or by an explict override. The Java Version Compliance setting in the Build Properties dialog is primarily for Eclipse to use as guidance on how to control editing (for example, flagging "enum", and use of annotations/generics/iterators), but the underlying selected JDK determines how classes get resolved.
Customer surveys are for companies who didn't pay proper attention to begin with.