Override annotation

Discussion in 'Java' started by neuneudr@yahoo.fr, May 29, 2008.

  1. Guest

    Hi all,

    since Java 1.5 we can use annotations, for example:

    @Override
    public String toString() {
    ...
    }

    Is there a technical reason why we have an '@Override'
    annotation but no '@Implements' annotation ?

    This is really just out of curiosity but any info is
    appreciated,

    Driss
     
    , May 29, 2008
    #1
    1. Advertising

  2. Mark Space Guest

    wrote:

    > Is there a technical reason why we have an '@Override'
    > annotation but no '@Implements' annotation ?


    There's just no difference between the two.
     
    Mark Space, May 29, 2008
    #2
    1. Advertising

  3. Daniel Pitts Guest

    Mark Space wrote:
    > wrote:
    >
    >> Is there a technical reason why we have an '@Override'
    >> annotation but no '@Implements' annotation ?

    >
    > There's just no difference between the two.

    Because not implementing a method is an error in itself.

    Not overriding a method is okay.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, May 29, 2008
    #3
  4. Guest

    On May 28, 5:45 pm, Daniel Pitts
    <> wrote:
    > Mark Space wrote:
    > > wrote:

    >
    > >> Is there a technical reason why we have an '@Override'
    > >> annotation but no '@Implements' annotation ?

    >
    > > There's just no difference between the two.

    >
    > Because not implementing a method is an error in itself.
    >
    > Not overriding a method is okay.


    OK, this is an interesting point but still...

    I'd like to do the following :

    public class A {

    void someMethod() {...}

    void someOtherMethod() {...}

    @Implements
    public int compareTo(Object o) {...}

    }

    and show to the compiler (or my IDE's realtime compiler)
    that my intent is that compareTo(...) implements a method
    from an interface.

    And in this case I'd like my IDE to tell me, in realtime,
    before I even waste time compiling this manually:

    "compareTo(...) is not implementing any method from any
    interface." (or a message similar to that one)

    Because, in this case, I forgot to add "implements Comparable" in
    the class's definition.

    Not sure that it makes sense, but I'd still like to have that.

    Put it another way: is there anything that technically
    prevents someone to write an '@Implements' annotation?

    Thanks again for your infos,

    Driss
     
    , May 29, 2008
    #4
  5. Daniel Pitts Guest

    wrote:
    > On May 28, 5:45 pm, Daniel Pitts
    > <> wrote:
    >> Mark Space wrote:
    >>> wrote:
    >>>> Is there a technical reason why we have an '@Override'
    >>>> annotation but no '@Implements' annotation ?
    >>> There's just no difference between the two.

    >> Because not implementing a method is an error in itself.
    >>
    >> Not overriding a method is okay.

    >
    > OK, this is an interesting point but still...
    >
    > I'd like to do the following :
    >
    > public class A {
    >
    > void someMethod() {...}
    >
    > void someOtherMethod() {...}
    >
    > @Implements
    > public int compareTo(Object o) {...}
    >
    > }
    >
    > and show to the compiler (or my IDE's realtime compiler)
    > that my intent is that compareTo(...) implements a method
    > from an interface.
    >
    > And in this case I'd like my IDE to tell me, in realtime,
    > before I even waste time compiling this manually:
    >
    > "compareTo(...) is not implementing any method from any
    > interface." (or a message similar to that one)
    >
    > Because, in this case, I forgot to add "implements Comparable" in
    > the class's definition.
    >
    > Not sure that it makes sense, but I'd still like to have that.
    >
    > Put it another way: is there anything that technically
    > prevents someone to write an '@Implements' annotation?
    >
    > Thanks again for your infos,
    >
    > Driss


    Interesting use case. Although, if you don't implement the appropriate
    interface, you're likely to get a compiler error on your uses of the
    class, if no where else but your unit tests. If not, you're either not
    testing your library correctly, or you don't need to implement that
    interface :)

    There isn't any technical reason you can't create an Implements
    annotation, although making your IDE/compiler recognize its intent might
    be more difficult.

    Oh, and just for the record, Comparable is a Generic interface, so it
    should be implements Comparable<A>

    What *I* find frustrating is that @Override works for abstract base
    classes, but not interfaces, which IMHO should be approximately the same
    thing in that regard.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, May 29, 2008
    #5
  6. Daniel Pitts Guest

    Zig wrote:
    > On Thu, 29 May 2008 01:12:52 -0400, Daniel Pitts
    > <> wrote:
    >
    >> What *I* find frustrating is that @Override works for abstract base
    >> classes, but not interfaces, which IMHO should be approximately the
    >> same thing in that regard.
    >>

    >
    > While true for Java 5, one of the more subtle changes to Java 6 was
    > making the @Override annotation valid in both cases now.
    >
    > HTH,
    >
    > -Zig

    Ah, that explains why my IDE doesn't complain, but ANT does (I really
    should set them both to the same JDK :) )

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, May 30, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chao
    Replies:
    1
    Views:
    10,055
    Tim Hubberstey
    May 6, 2004
  2. rajan

    Back Annotation simulations

    rajan, Aug 7, 2004, in forum: VHDL
    Replies:
    4
    Views:
    4,508
    Ansgar Bambynek
    Aug 10, 2004
  3. =?Utf-8?B?c3VyZXNo?=
    Replies:
    2
    Views:
    415
    Patrice
    Oct 26, 2005
  4. Raymond McCrae
    Replies:
    2
    Views:
    1,605
    Raymond McCrae
    Mar 3, 2004
  5. Y HA
    Replies:
    32
    Views:
    769
    John B. Matthews
    Dec 11, 2013
Loading...

Share This Page