Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!mit.eternal-september.org!.POSTED!not-for-mail From: Simon Lewis Newsgroups: comp.lang.java.programmer Subject: Re: @java.lang.DontOverride Date: Sun, 11 May 2014 11:03:12 +0200 Organization: Lewis Lines: 15 Message-ID: <87bnv47kmn.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mit.eternal-september.org; posting-host="4a26d5f9613c414e2e4817c03702b3c3"; logging-data="19502"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WWeaVl1NXmKDbBA1pHk1MFwbjnmcLruo=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:L570Lv4Gwf63ZUymlt/cTcxPJ9k= sha1:XZ50GrZ+D6Oj8hmwFEJvVlYh+wY= Xref: csiph.com comp.lang.java.programmer:28432 ram@zedat.fu-berlin.de (Stefan Ram) writes: > class Example extends javax.swing.JComponent > { public boolean isValid(){ return true; }} > > I do not want to override any method of JComponent with my method. > I just want to add a new method. But now or in future versions of > Swing there might be an »isValid« method in JComponent. So I'd like > to have a @java.lang.DontOverride annotation with the following > meaning: »Aborts compilation if any base class has a non-private > method of the same name.« Why do we have @java.lang.Ovverride, but > not the opposite? Or have I missed something? A rare requirement but you could just try and call the superclass method and catch any exception that results and call your own one.