Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 546
Marco Ferrari Avatar asked Sep 20 '13 14:09

Marco Ferrari


People also ask

Can we annotate interface in Java?

Annotation is defined like a ordinary Java interface, but with an '@' preceding the interface keyword (i.e., @interface ). You can declare methods inside an annotation definition (just like declaring abstract method inside an interface). These methods are called elements instead.


1 Answers

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.

like image 58
AMDG Avatar answered Oct 27 '22 07:10

AMDG