问题
The following interface:
import javax.xml.ws.Action;
public interface AnnotationsTestInterface {
@Action
public void annotatedMethod();
}
And an implementing class:
public class Impl implements AnnotationsTestInterface {}
At this point Eclipse asks me to add unimplemented methods (I choose this) or make the class abstract.
After the addition the class looks like this:
import javax.xml.ws.Action;
public class Impl implements AnnotationsTestInterface {
@Override
@Action
public void annotatedMethod() {
// TODO Auto-generated method stub
}
}
It correctly writes the Action annotation.
On another Eclipse instance (same version, different user) the "Add unimplemented methods" action results in this (no @Action annotation):
public class Impl implements AnnotationsTestInterface {
@Override
public void annotatedMethod() {
// TODO Auto-generated method stub
}
}
Is there an option somewhere that deals with this?
Note that the execution environment is set on Java SE 6, with a JDK 6.
回答1:
On eclipse, go to Window->Preferences->Java->Code Style->Clean Up and look around in there. If not there, look around in Code Style. You ought to find it! If I had to guess, if @Action isn't showing up in the TODO auto-generated stuff smutzle and what not, you have an old version of eclipse, or it wasn't configured to do that.
回答2:
I had a problem with the auto-generated stuff in eclipse before. In eclipse kelper Window>preferences>java>code style > code templates
I think that the setting you want is interface body.
This setting contains all of the default code for newly created files/methods
来源:https://stackoverflow.com/questions/18919238/why-eclipse-does-not-include-annotations-when-implementing-methods-from-a-java-i