Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #16261
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: @Override |
| Date | 2012-07-23 13:05 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <16435c0e-fd35-4f48-a6b7-5e6cd5cbf107@googlegroups.com> (permalink) |
| References | <75036e8b-8b5f-4ea4-aef7-c063249f5707@googlegroups.com> <juk6la$l43$1@dont-email.me> |
markspace wrote:
> bob smith wrote:
> Is it really necessary to write @Override when you override or is
> this just "a good thing"?
Since when does "a good thing" ever deserve a "just"?
If it's a good thing, what's your objection?
Did you read the docs on '@Override'?
<http://docs.oracle.com/javase/specs/jls/se7/html/jls-9.html#jls-9.6.3.4>
<http://docs.oracle.com/javase/7/docs/api/java/lang/Override.html>
Why not?
Seriously, why in the world would you not want to use '@Override'?
Based on the documentation, now that you're aware of it, rephrase
your question as "What are the advantages and disadvantages of
'@Override'?" Then evaluate its utility.
> Well, it's "just [sic] a good thing," but it's *really* a good thing. If you
> were programming professionally, you'd expect your boss (or coworkers,
> say during a code review) to insist that you use @Override wherever
> appropriate.
>
> In short, "just do it."
OP: There is benefit to using '@Override' and serious risk of harm if you don't.
Consider 'Object#equals()'.
public class BadEquals
{
private String attribute = "";
public String getAttribute() { return attribute; }
public void setAttribute(String attr) { this.attribute = (attr == null? "" : attr); }
public boolean equals(BadEquals other)
{
if (this == other)
{
return true;
}
if (other == null)
{
return false;
}
return getAttribute().equals(other.getAttribute());
}
}
Let's say you have another class that uses a collection of 'BadEquals'.
Without '@Override', as shown above, you won't catch that bug until
runtime.
With it, you'll catch it at compile time.
--
Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
@Override bob smith <bob@coolfone.comze.com> - 2012-07-23 11:30 -0700
Re: @Override Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-23 20:52 +0200
Re: @Override markspace <-@.> - 2012-07-23 11:54 -0700
Re: @Override Lew <lewbloch@gmail.com> - 2012-07-23 13:05 -0700
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 19:54 -0400
Re: @Override "John B. Matthews" <nospam@nospam.invalid> - 2012-07-23 15:56 -0400
Re: @Override Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-07-23 14:19 -0700
Re: @Override rossum <rossum48@coldmail.com> - 2012-07-24 13:09 +0100
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-24 21:29 -0400
Re: @Override Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-24 09:04 -0400
Re: @Override Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-23 16:35 -0400
Re: @Override Lew <lewbloch@gmail.com> - 2012-07-23 13:59 -0700
Re: @Override Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-23 23:40 +0200
Re: @Override Lew <lewbloch@gmail.com> - 2012-07-23 14:51 -0700
Re: @Override Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-24 00:08 +0200
Re: @Override Lew <lewbloch@gmail.com> - 2012-07-23 16:57 -0700
Re: @Override Robert Klemme <shortcutter@googlemail.com> - 2012-07-24 09:46 +0200
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 19:58 -0400
Re: @Override Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-23 22:16 -0400
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 22:57 -0400
Re: @Override Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-23 23:47 -0400
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-24 21:35 -0400
Re: @Override Jim Janney <jjanney@shell.xmission.com> - 2012-07-26 20:00 -0600
Re: @Override Gene Wirchenko <genew@ocis.net> - 2012-07-23 14:01 -0700
Re: @Override Silvio Bierman <silvio@moc.com> - 2012-07-24 00:22 +0200
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 19:53 -0400
Re: @Override Gene Wirchenko <genew@ocis.net> - 2012-07-23 18:59 -0700
Re: @Override Silvio Bierman <silvio@moc.com> - 2012-07-24 22:57 +0200
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-24 21:24 -0400
Re: @Override Robert Klemme <shortcutter@googlemail.com> - 2012-07-24 15:36 +0200
Re: @Override Gene Wirchenko <genew@ocis.net> - 2012-07-24 09:54 -0700
Re: @Override Silvio Bierman <silvio@moc.com> - 2012-07-24 23:14 +0200
Re: @Override Robert Klemme <shortcutter@googlemail.com> - 2012-07-25 07:57 +0200
Re: @Override Gene Wirchenko <genew@ocis.net> - 2012-07-25 10:34 -0700
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-25 14:54 -0400
Re: @Override Wanja Gayk <brixomatic@yahoo.com> - 2012-07-30 14:42 +0200
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-24 21:20 -0400
Re: @Override Lew <noone@lewscanon.com> - 2012-07-25 06:26 -0700
Re: @Override Arne Vajhøj <arne@vajhoej.dk> - 2012-07-25 17:16 -0400
Re: @Override Roedy Green <see_website@mindprod.com.invalid> - 2012-07-23 20:59 -0700
Re: @Override Wanja Gayk <brixomatic@yahoo.com> - 2012-07-24 16:06 +0200
csiph-web