Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > @Override

Reply
Thread Tools

@Override

 
 
Roedy Green
Guest
Posts: n/a
 
      07-24-2012
On Mon, 23 Jul 2012 11:30:22 -0700 (PDT), bob smith
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>Is it really necessary to write @Override when you override or is this just "a good thing"?


I asked for this in the days of Java 1.1. The syntax is a little
different that I had in mind, but it still has the same function. So
obviously I am keen on it.

I wanted it because sometimes I would override some method, but spell
it a little incorrectly or get the signature a little off. Then I
created an ambiguity sometimes calling the base method and sometimes
my new one. With @Override, if I don't get the match exact, I get an
error message.

I am big on ways for programs to cross check themselves for
consistency.
--
Roedy Green Canadian Mind Products
http://mindprod.com
The greatest shortcoming of the human race is our inability to understand the exponential function.
~ Dr. Albert A. Bartlett (born: 1923-03-21 age: 89)
http://www.youtube.com/watch?v=F-QA2rkpBSY


 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      07-24-2012
On 23.07.2012 22:59, Lew wrote:
> Add the third benefit that I mentioned upthread. Aren't they enough now?


Are variant of this is where the super class or interface is in a
library and a later version removed the method. You'll immediately
notice when replacing the lib with the newer version. This is a good
thing (being noticed - not removing something from a public API) and you
are immediately aware that your method won't be invoked the same way as
it used to be.

Granted this should be a rare situation but - for example - if the
library method had been deprecated and you somehow missed adjusting your
code to the imminent removal the compiler will force it on you once it
is gone.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      07-24-2012
On 7/23/2012 5:19 PM, Peter Duniho wrote:
>[...]
> I will admit that the number of times it's helped me avoid a mistake are
> far and few between. But it's happened, and it's certainly no large
> inconvenience to have to include "override" (in fact, at least with the
> Visual Studio IDE, it's a convenience, as VS will pop up a list of
> overridable methods, and then auto-generate a skeleton method to fill in
> for the override...maybe Eclipse, NetBeans, etc. would do the same?).


NetBeans will do two things about @Override (maybe more). It
will flag an overriding method that lacks an @Override annotation
and suggest that you add it (which you can do with a shortcut).
A feature I find even more convenient is that it notices when you
attempt to intantiate an abstract class, and suggests that you
provide overrides for the missing methods. Another shortcut, and
presto! it writes skeletons for the missing methods, with @Override
already in place. Saves the bother of hunting up the exact spelling
of a method name.

Illustration: If I type

button.addActionListener(new ActionListener(){});

.... NetBeans tells me I've failed to implement abstract methods.
After Alt-Enter and a confirming Enter, it rewrites my code as

button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException(
"Not supported yet.");
}
});

.... which I find very helpful, especially for interfaces that
have several abstract methods. (I've even been known to let
NetBeans expand MouseListener, then change it to MouseAdapter
and delete the auto-written methods I don't care about, just
to be sure I've got everything spelled properly.)

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      07-24-2012
On 24.07.2012 00:22, Silvio Bierman wrote:
> Using an annotation is, as with
> almost all uses of annotations, a poor attempt at making up for the lack
> of a proper language feature.


That is nonsense. The mere fact that users can define their own
annotations along with handling these annotations demonstrates that
annotations solve problems which cannot be tackled by changing a
language's syntax. Annotations add *arbitrary* meta data to language
constructs; if all these would have to be handled by a language change
you would need a new Java for every custom library which requires
additional meta data.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      07-24-2012
On Tue, 24 Jul 2012 15:36:15 +0200, Robert Klemme
<(E-Mail Removed)> wrote:

>On 24.07.2012 00:22, Silvio Bierman wrote:
>> Using an annotation is, as with
>> almost all uses of annotations, a poor attempt at making up for the lack
>> of a proper language feature.

>
>That is nonsense. The mere fact that users can define their own
>annotations along with handling these annotations demonstrates that
>annotations solve problems which cannot be tackled by changing a
>language's syntax. Annotations add *arbitrary* meta data to language
>constructs; if all these would have to be handled by a language change
>you would need a new Java for every custom library which requires
>additional meta data.


Let me add that useful annotations added by one user and group of
users might be useful only for them so changing the language would not
be a good fit.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Silvio Bierman
Guest
Posts: n/a
 
      07-24-2012
On 07/24/2012 01:53 AM, Arne Vajh°j wrote:
> On 7/23/2012 6:22 PM, Silvio Bierman wrote:
>


SNIP

> True.
>
> But we are still waiting for the language that gets everything right.
>
> Arne
>
>


There is no such language and there never will be since it is and always
will be a moving target.

I am not saying that Scala is the perfect language for anyone, let alone
for everyone. But for me it is so extremely much closer to what I
need/want than Java that, since it is already available, it would be
stupid FOR ME not to use it. The fact that Scala happens to fix a lot of
Java design errors is a minor point, by the way.

For others it may be Groovy, Clojure or perhaps even Ruby if you are not
tied to the JVM. And for many staying with Java may be the most sensible
thing to do. But even then, it remains a fact of life that there will be
JVM languages that chose to fix Java omissions and mistakes.

For me one thing I like is that the Scala language developers are not
stuck on backward compatibility. They are not afraid to fix things, even
if that will break existing code. The language comes/exists in versions
and existing code may be tied to an older version. Does not have to be a
problem at all and the owner of the code can choose to update it if and
when he desires so.

If only they had done that with Java they could have fixed a lot of
annoying things. Now newer versions introduce new language features but
developers can not use them since their users do not want to upgrade to
the latest JVM. That is also a version problem, but then backwards.

Silvio

 
Reply With Quote
 
Silvio Bierman
Guest
Posts: n/a
 
      07-24-2012
On 07/24/2012 03:36 PM, Robert Klemme wrote:
> On 24.07.2012 00:22, Silvio Bierman wrote:
>> Using an annotation is, as with
>> almost all uses of annotations, a poor attempt at making up for the lack
>> of a proper language feature.

>
> That is nonsense. The mere fact that users can define their own
> annotations along with handling these annotations demonstrates that
> annotations solve problems which cannot be tackled by changing a
> language's syntax. Annotations add *arbitrary* meta data to language
> constructs; if all these would have to be handled by a language change
> you would need a new Java for every custom library which requires
> additional meta data.
>
> Kind regards
>
> robert
>


Well, I already really dislike annotations for their use in frameworks
like for example Hibernate or for all examples I have seen in "user code".
But to use it for plain language level constructs like @Override,
@NotNull etc. is plain ugly. Why have keywords like final, public, etc.
at all, then?

Someone really disliked the lack of an override keyword and since adding
that would break existing code they opted to introduce an annotation.
Perhaps we should introduce some to repair the design error that is the
combination of private, protected and public keywords with the ludicrous
default of package visibility when none of them is specified?

This way the language gets polluted using the generic annotation hammer.
Leave it be or actually fix it! I would applaud a bold language revision
that breaks backward compatibility for the benefit of fixing the
language. I could even imagine an annotation that could hint the
compiler at what language version a source is targeting.

Silvio

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      07-25-2012
On 7/24/2012 9:36 AM, Robert Klemme wrote:
> On 24.07.2012 00:22, Silvio Bierman wrote:
>> Using an annotation is, as with
>> almost all uses of annotations, a poor attempt at making up for the lack
>> of a proper language feature.

>
> That is nonsense. The mere fact that users can define their own
> annotations along with handling these annotations demonstrates that
> annotations solve problems which cannot be tackled by changing a
> language's syntax. Annotations add *arbitrary* meta data to language
> constructs; if all these would have to be handled by a language change
> you would need a new Java for every custom library which requires
> additional meta data.


True.

There are two types of annotations:
* those acting as a supplement to the language
* those intended for runtime reflection

Arne


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      07-25-2012
On 7/24/2012 4:57 PM, Silvio Bierman wrote:
> On 07/24/2012 01:53 AM, Arne Vajh°j wrote:
>> On 7/23/2012 6:22 PM, Silvio Bierman wrote:
>> True.
>>
>> But we are still waiting for the language that gets everything right.


> There is no such language and there never will be since it is and always
> will be a moving target.


And both the problems to be solved and the people trying to solve them
are different.

> I am not saying that Scala is the perfect language for anyone, let alone
> for everyone. But for me it is so extremely much closer to what I
> need/want than Java that, since it is already available, it would be
> stupid FOR ME not to use it. The fact that Scala happens to fix a lot of
> Java design errors is a minor point, by the way.


I also like Scala.

But I do not see it overtake the role of Java.

Two reasons:
- the language is not stable enough
- the language is too difficult

> For others it may be Groovy, Clojure or perhaps even Ruby if you are not
> tied to the JVM.


You can run Ruby in the JVM.

> And for many staying with Java may be the most sensible
> thing to do. But even then, it remains a fact of life that there will be
> JVM languages that chose to fix Java omissions and mistakes.
>
> For me one thing I like is that the Scala language developers are not
> stuck on backward compatibility. They are not afraid to fix things, even
> if that will break existing code. The language comes/exists in versions
> and existing code may be tied to an older version. Does not have to be a
> problem at all and the owner of the code can choose to update it if and
> when he desires so.
>
> If only they had done that with Java they could have fixed a lot of
> annoying things. Now newer versions introduce new language features but
> developers can not use them since their users do not want to upgrade to
> the latest JVM. That is also a version problem, but then backwards.


A high level of backwards compatibility is a requirement in much
of the enterprise market.

Arne


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      07-25-2012
On 7/24/2012 8:09 AM, rossum wrote:
> On Mon, 23 Jul 2012 14:19:16 -0700, Peter Duniho
> <(E-Mail Removed)> wrote:
>> in fact, at least with the Visual Studio IDE, it's a convenience, as
>> VS will pop up a list of overridable methods, and then auto-generate
>> a skeleton method to fill in for the override...maybe Eclipse,
>> NetBeans, etc. would do the same?

> NetBeans does that: Alt+Insert or right click and select "Insert
> Code". I don't use Eclipse, so I can't comment on that IDE.


right click
refactor
override/implements methods
pick what one want

Arne


 
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




Advertisments