You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Raymond Feng <en...@gmail.com> on 2010/06/25 21:00:15 UTC
Please don't add @Override to methods in the class that implements an interface
Hi,
The @Override is used to annotate a method that overrides the method from the super class. In case of implementing methods from an interface, please don't use it. The Eclipse compiler will catch such problems and report as errors.
For example,
public interface A {
String m1();
}
public class AImpl implements A {
// DO NOT add @Override here
public String m1() {
return "A";
}
}
public class BImpl extends AImpl {
@Override // This is correct
public String m1() {
return "B";
}
}
Thanks,
Raymond
________________________________________________________________
Raymond Feng
rfeng@apache.org
Apache Tuscany PMC member and committer: tuscany.apache.org
Co-author of Tuscany SCA In Action book: www.tuscanyinaction.com
Personal Web Site: www.enjoyjava.com
________________________________________________________________
Re: Please don't add @Override to methods in the class that
implements an interface
Posted by Simon Laws <si...@googlemail.com>.
On Wed, Jun 30, 2010 at 10:16 AM, Mike Edwards
<mi...@gmail.com> wrote:
> Raymond Feng wrote:
>>
>> Interesting. I'm on Eclipse Helios and it seems to complain about the
>> @Override on implementing a method from the interface.
>> Eclipse does have a page to tweak this: Preferences --> Java --> Compiler
>> --> Annotations.
>>
>> Raymond
>
> <snip>
>>>
>>> Hi Raymond
>>>
>>> I agree that it's odd to have @Override mark a method that simply
>>> implements an interface method.
>>>
>>> However I just experimented and for me Eclipse (Ganymede) in its
>>> default configuration doesn't complain about it and positively
>>> encourages it by automatically adding them when I ask it to add
>>> implementations for any methods from an interface that a class doesn't
>>> yet implement.
>>>
>>> Do you have local configuration that alters this behaviour?
>>>
>>> Simon
>
> Folks,
>
> Following up on this.
>
> On Eclipse 3.4.1, there is no
>
> Preferences --> Java --> Compiler --> Annotations
>
> option.
>
> Instead, there is:
>
> Preferences --> Java --> Code Style --> "Add @Override annotation for new
> overriding methods"
>
> This one is checked by default and I am sure that this is the source of the
> problems that Raymond has experienced since it is very natural to use the
> automated facility for implementing the methods of an interface. It is
> curious that Eclipse have changed their mind on this one causing developers
> grief when moving between Eclipse releases, since unless there is good
> reason, most developers will use the Eclipse defaults without even thinking
> about them.
>
>
> Yours, Mike.
>
>
Thanks Mike
I unchecked the option but I suspect that that means the it won't now
add @Override even when they are appropriate.
Simon
--
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com
Re: Please don't add @Override to methods in the class that implements
an interface
Posted by Mike Edwards <mi...@gmail.com>.
Raymond Feng wrote:
> Interesting. I'm on Eclipse Helios and it seems to complain about the
> @Override on implementing a method from the interface.
>
> Eclipse does have a page to tweak this: Preferences --> Java -->
> Compiler --> Annotations.
>
> Raymond
<snip>
>> Hi Raymond
>>
>> I agree that it's odd to have @Override mark a method that simply
>> implements an interface method.
>>
>> However I just experimented and for me Eclipse (Ganymede) in its
>> default configuration doesn't complain about it and positively
>> encourages it by automatically adding them when I ask it to add
>> implementations for any methods from an interface that a class doesn't
>> yet implement.
>>
>> Do you have local configuration that alters this behaviour?
>>
>> Simon
Folks,
Following up on this.
On Eclipse 3.4.1, there is no
Preferences --> Java --> Compiler --> Annotations
option.
Instead, there is:
Preferences --> Java --> Code Style --> "Add @Override annotation for new overriding methods"
This one is checked by default and I am sure that this is the source of the problems that Raymond
has experienced since it is very natural to use the automated facility for implementing the methods
of an interface. It is curious that Eclipse have changed their mind on this one causing developers
grief when moving between Eclipse releases, since unless there is good reason, most developers will
use the Eclipse defaults without even thinking about them.
Yours, Mike.
Re: Please don't add @Override to methods in the class that implements an interface
Posted by Raymond Feng <en...@gmail.com>.
Interesting. I'm on Eclipse Helios and it seems to complain about the @Override on implementing a method from the interface.
Eclipse does have a page to tweak this: Preferences --> Java --> Compiler --> Annotations.
Raymond
________________________________________________________________
Raymond Feng
rfeng@apache.org
Apache Tuscany PMC member and committer: tuscany.apache.org
Co-author of Tuscany SCA In Action book: www.tuscanyinaction.com
Personal Web Site: www.enjoyjava.com
________________________________________________________________
On Jun 28, 2010, at 5:14 AM, Simon Laws wrote:
> On Fri, Jun 25, 2010 at 8:00 PM, Raymond Feng <en...@gmail.com> wrote:
>> Hi,
>> The @Override is used to annotate a method that overrides the method from
>> the super class. In case of implementing methods from an interface, please
>> don't use it. The Eclipse compiler will catch such problems and report as
>> errors.
>> For example,
>> public interface A {
>> String m1();
>> }
>>
>> public class AImpl implements A {
>> // DO NOT add @Override here
>> public String m1() {
>> return "A";
>> }
>> }
>>
>> public class BImpl extends AImpl {
>> @Override // This is correct
>> public String m1() {
>> return "B";
>> }
>> }
>>
>> Thanks,
>> Raymond
>> ________________________________________________________________
>> Raymond Feng
>> rfeng@apache.org
>> Apache Tuscany PMC member and committer: tuscany.apache.org
>> Co-author of Tuscany SCA In Action book: www.tuscanyinaction.com
>> Personal Web Site: www.enjoyjava.com
>> ________________________________________________________________
>>
>
> Hi Raymond
>
> I agree that it's odd to have @Override mark a method that simply
> implements an interface method.
>
> However I just experimented and for me Eclipse (Ganymede) in its
> default configuration doesn't complain about it and positively
> encourages it by automatically adding them when I ask it to add
> implementations for any methods from an interface that a class doesn't
> yet implement.
>
> Do you have local configuration that alters this behaviour?
>
> Simon
>
>
> --
> Apache Tuscany committer: tuscany.apache.org
> Co-author of a book about Tuscany and SCA: tuscanyinaction.com
Re: Please don't add @Override to methods in the class that
implements an interface
Posted by Simon Laws <si...@googlemail.com>.
On Fri, Jun 25, 2010 at 8:00 PM, Raymond Feng <en...@gmail.com> wrote:
> Hi,
> The @Override is used to annotate a method that overrides the method from
> the super class. In case of implementing methods from an interface, please
> don't use it. The Eclipse compiler will catch such problems and report as
> errors.
> For example,
> public interface A {
> String m1();
> }
>
> public class AImpl implements A {
> // DO NOT add @Override here
> public String m1() {
> return "A";
> }
> }
>
> public class BImpl extends AImpl {
> @Override // This is correct
> public String m1() {
> return "B";
> }
> }
>
> Thanks,
> Raymond
> ________________________________________________________________
> Raymond Feng
> rfeng@apache.org
> Apache Tuscany PMC member and committer: tuscany.apache.org
> Co-author of Tuscany SCA In Action book: www.tuscanyinaction.com
> Personal Web Site: www.enjoyjava.com
> ________________________________________________________________
>
Hi Raymond
I agree that it's odd to have @Override mark a method that simply
implements an interface method.
However I just experimented and for me Eclipse (Ganymede) in its
default configuration doesn't complain about it and positively
encourages it by automatically adding them when I ask it to add
implementations for any methods from an interface that a class doesn't
yet implement.
Do you have local configuration that alters this behaviour?
Simon
--
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com