Hi,
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.
From the original compile error, it looks like it does understand @Override Annotation but disagrees that it is valid. Perhaps show us more code (like at least the two method signatures)
Lisa Ray
Greenhorn
Joined: Mar 05, 2009
Posts: 22
posted
0
If there was some issue with the method override, the Eclipse compiler would have reported that. Still, I'm sharing the code.
[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?)
Lisa Ray
Greenhorn
Joined: Mar 05, 2009
Posts: 22
posted
0
Carol wrote:
Looks like it is a difference between java 5 & 6.
I tried doing the following changes and failed:
And,
Carol, What needs to be done to get off this issue?
In anticipation.
Carol Enderlin
drifter
Ranch Hand
Joined: Oct 10, 2000
Posts: 1348
posted
0
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!!!
Lisa Ray
Greenhorn
Joined: Mar 05, 2009
Posts: 22
posted
0
Hi All,
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.
in 1.5, @Override is accepted only in the case of extending a class. If you are implementing a method in an interface, then you cannot use this annotation.
In 1.6, @Override is acceptable when implementing a method from an interface.
If you need Ant to accept the 1.6 usage, then set the compiler source compliance to "1.6" in your build.xml: <javac source="1.6"..... />
Interestingly, this change from Java 5 to Java 6 apparently wasn't documented anywhere: http://blogs.sun.com/ahe/entry/override_snafu thus taking many people (including myself :-) by surprise.
Ulf Dittmer wrote:Interestingly, this change from Java 5 to Java 6 apparently wasn't documented anywhere: http://blogs.sun.com/ahe/entry/override_snafu thus taking many people (including myself :-) by surprise.
And a Java 6 compiler in Java 5 mode doesn't tell you about it. Which means Ulf has caught me using @Override in a way that doesn't work on a real Java 5 compiler a number of times