Path: csiph.com!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "John B. Matthews" Newsgroups: comp.lang.java.programmer Subject: Re: Use of @Override when implementing interfaces Date: Wed, 11 Dec 2013 00:55:17 -0500 Organization: The Wasteland Lines: 65 Message-ID: References: <52a67735$0$293$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 11 Dec 2013 05:55:18 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="d17dee34624b7b363488e8f2f4ab0076"; logging-data="21160"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6GuQWBMevbxciL1kdszLwo0mRIu+0j3g=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: <52a67735$0$293$14726298@news.sunsite.dk> Cancel-Lock: sha1:YmUfxtx3jc0nO/43c0nzWfeNc10= Xref: csiph.com comp.lang.java.programmer:26833 On 12/9/13, 9:06 PM, Arne Vajhøj wrote: > On 12/6/2013 2:01 AM, Fredrik Jonson wrote: >> Y HA wrote: >> >>> class Task implements Runnable { >>> @Override >>> public void run() { >>> System.out.println("Run method overridden in Task class"); >>> } >>> } >> >> Sorry, I can't help with the problem, but the code made me curious. >> >> Is it commont practice to use @Override when implementing interface >> methods? Assuming that the method has not been implemented by a >> superclass. >> >> Obviously, the annotation is technically allowed, still it isn't really >> possible to override an implementation that does not exist. And it >> doesn't add type safety to the code, if your method signature doesn't >> match the method signature of the interface, the implementing class >> won't compile. > > @Override was added in 1.5, but I believe that @Override was first > added in 1.6. > > @Override in case of super class with non abstract method makes a > lot of sense as it turns some runtime bugs into compile time bugs. > > @Override in case of super class with abstract method or > interface is a bit less obvious. > > I don't use it myself. > > But Eclipse generate them, so they are probably relative common. This matches my recollection. I've got some short examples from the period that have the (permitted) superclass override annotation static class MyLabel extends JLabel { @Override public Dimension getPreferredSize() { ... } } and the (forbidden) interface implementation annotation in a comment. public static void main(String[] argv) { EventQueue.invokeLater(new Runnable() { //@Override public void run() { ... } }); More details on the 1.5/1.6 change are cited here: . -- John B. Matthews trashgod at gmail dot com