Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Override annotation

Reply
Thread Tools

Override annotation

 
 
neuneudr@yahoo.fr
Guest
Posts: n/a
 
      05-28-2008
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
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      05-29-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

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


There's just no difference between the two.
 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      05-29-2008
Mark Space wrote:
> (E-Mail Removed) 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/>
 
Reply With Quote
 
neuneudr@yahoo.fr
Guest
Posts: n/a
 
      05-29-2008
On May 28, 5:45 pm, Daniel Pitts
<(E-Mail Removed)> wrote:
> Mark Space wrote:
> > (E-Mail Removed) 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
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      05-29-2008
(E-Mail Removed) wrote:
> On May 28, 5:45 pm, Daniel Pitts
> <(E-Mail Removed)> wrote:
>> Mark Space wrote:
>>> (E-Mail Removed) 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/>
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      05-30-2008
Zig wrote:
> On Thu, 29 May 2008 01:12:52 -0400, Daniel Pitts
> <(E-Mail Removed)> 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/>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create annotation on System.Web.UI.WebControls.Image =?Utf-8?B?c3VyZXNo?= ASP .Net 2 10-26-2005 12:01 PM
Back Annotation simulations rajan VHDL 4 08-10-2004 07:57 AM
back-annotation SDF Timing Simulation Chao VHDL 1 05-06-2004 05:23 PM
java.text.Annotation srini Java 0 04-23-2004 11:25 PM
Getting Annotation for a Return Type (Java 1.5 Beta) Raymond McCrae Java 2 03-03-2004 06:37 PM



Advertisments