Why Eclipse does not include annotations when implementing methods from a Java interface?

爱⌒轻易说出口 提交于 2019-12-21 04:08:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!