Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26785

Re: Use of @Override when implementing interfaces

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Use of @Override when implementing interfaces
Date Sun, 08 Dec 2013 16:45:34 -0500
Organization A noiseless patient Spider
Lines 54
Message-ID <l82p9t$9pm$1@dont-email.me> (permalink)
References <d0685bbc-5d5d-47d0-a264-e79debf00b3d@googlegroups.com> <slrnla2tii.76o.fredrik@biggles.jonson.org> <52a1867c$0$2911$e4fe514c@news2.news.xs4all.nl> <796271a4-11a0-402c-85ff-0f91556c8e7a@googlegroups.com> <l7vbhp$pdi$1@dont-email.me> <Override-20131207164235@ram.dialup.fu-berlin.de> <b8ada45d-d9f6-440d-943a-149d05318136@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sun, 8 Dec 2013 21:45:33 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="10038"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vzFvX2HLArzLWBnx2eMZM"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
In-Reply-To <b8ada45d-d9f6-440d-943a-149d05318136@googlegroups.com>
Cancel-Lock sha1:VIPAg+xvFg7OP0pTBcTdGLnfUx0=
Xref csiph.com comp.lang.java.programmer:26785

Show key headers only | View raw


On 12/8/2013 3:02 PM, Y HA wrote:
>
>
> using @java.lang.Override seems to have worked...
>
> why there was the need to specify java.lang.Override ?

     Because (as two or three people have explained) `Override' is
just a name, not something built in to the compiler like `throw'
or `float'.  When your source contains `@Override', the compiler
realizes `Override' must be the name of something and sees that it
is an unqualified name: The package that defines the name has not
been specified.  So the compiler searches in various places,
looking for a package that defines `Override'.

     Usually, the compiler finds `Override' in the `java.lang'
package and concludes that the full name is `java.lang.Override'.
This particular definition of `Override' is of the right kind to
be used as an annotation, so all is well.  But in your case there
was another `Override' definition, a class (probably in a file
named "Override.java") with `Override' as its name.  The compiler
found this other `Override' first, and said "Aha! `Override' is
shorthand for `whatever.package.Override'."  Unfortunately, your
`Override' was entirely the wrong sort of thing: A class, not a
sub-interface of `java.lang.annotation.Annotation'.

     When you wrote `@java.lang.Override' in your source, the
compiler knew immediately what package contained the `Override'
definition that was needed.  So the compiler didn't need to
search for anything, didn't find your non-Annotation `Override',
and went right ahead with the `java.lang.Override' version.

     Names in Java are not globally unique; different packages
can define classes and interfaces and enums with the same name.
Java SE 7 includes two different things named `Parser', three
named `AttributeList', four named `Attribute', five named `Element',
and so it goes. How can all these colliding names coexist?  They
are in different packages.

     Usually, you import the package that defines the particular
kind of `FooBar' your source refers to (the compiler makes the
java and java.lang packages visible without the need to import).
Then you write `FooBar' in the source, and the compiler finds the
right definition among your imports.  But occasionally you need
to deal with more than one kind of `FooBar' in the same source:
For example, you may use the `java.util.List' interface and the
`java.awt.List' class at the same time.  When this happens, you
need to write out the full name; `List' by itself is ambiguous
when there's more than one kind of `List' in play.  Similarly,
`Override' by itself is ambiguous when there's more than one.

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

@override annotation not working correctly javac version _ 1.7.0_25 Y HA <yuriha@gmail.com> - 2013-12-05 14:42 -0800
  Re: @override annotation not working correctly javac version _ 1.7.0_25 Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-12-05 18:25 -0500
    Re: @override annotation not working correctly javac version _ 1.7.0_25 Y HA <yuriha@gmail.com> - 2013-12-05 16:13 -0800
      Re: @override annotation not working correctly javac version _ 1.7.0_25 Y HA <yuriha@gmail.com> - 2013-12-05 17:00 -0800
      Re: @override annotation not working correctly javac version _ 1.7.0_25 Y HA <yuriha@gmail.com> - 2013-12-05 17:03 -0800
        Re: @override annotation not working correctly javac version _ 1.7.0_25 Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-12-05 20:42 -0500
          Re: @override annotation not working correctly javac version _ 1.7.0_25 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-12-07 19:15 +0000
  Re: @override annotation not working correctly javac version _ 1.7.0_25 "John B. Matthews" <nospam@nospam.invalid> - 2013-12-05 21:49 -0500
  Use of @Override when implementing interfaces (was: @override annotation not working...) Fredrik Jonson <fredrik@jonson.org> - 2013-12-06 07:01 +0000
    Re: Use of @Override when implementing interfaces Silvio <silvio@internet.com> - 2013-12-06 09:10 +0100
      Re: Use of @Override when implementing interfaces Y HA <yuriha@gmail.com> - 2013-12-06 07:08 -0800
        another error with @Override  with another code Y HA <yuriha@gmail.com> - 2013-12-06 07:25 -0800
          Re: another error with @Override  with another code "John B. Matthews" <nospam@nospam.invalid> - 2013-12-06 11:29 -0500
            Re: another error with @Override  with another code Y HA <yuriha@gmail.com> - 2013-12-06 09:21 -0800
              Re: another error with @Override  with another code "John B. Matthews" <nospam@nospam.invalid> - 2013-12-07 00:26 -0500
                Re: another error with @Override  with another code Knute Johnson <september@knutejohnson.com> - 2013-12-06 21:57 -0800
                Re: another error with @Override  with another code Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-12-07 08:44 -0500
              Re: another error with @Override  with another code "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-12-07 11:12 +0000
        Re: Use of @Override when implementing interfaces Stanimir Stamenkov <s7an10@netscape.net> - 2013-12-07 16:32 +0200
          Re: Use of @Override when implementing interfaces Y HA <yuriha@gmail.com> - 2013-12-08 12:02 -0800
            Re: Use of @Override when implementing interfaces Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-12-08 21:27 +0000
              Re: Use of @Override when implementing interfaces Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-12-08 23:43 +0000
            Re: Use of @Override when implementing interfaces Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-12-08 16:45 -0500
    Re: Use of @Override when implementing interfaces Jeff Higgins <jeff@invalid.invalid> - 2013-12-06 09:51 -0500
    Re: Use of @Override when implementing interfaces leif.roar@invalid.com (Leif Roar Moldskred) - 2013-12-06 09:36 -0600
      Re: Use of @Override when implementing interfaces Y HA <yuriha@gmail.com> - 2013-12-06 07:41 -0800
      Re: Use of @Override when implementing interfaces markspace <markspace@nospam.nospam> - 2013-12-06 08:18 -0800
    Re: Use of @Override when implementing interfaces v_borchert@despammed.com (Volker Borchert) - 2013-12-07 07:14 +0000
      Re: Use of @Override when implementing interfaces Wayne <nospam@all.invalid> - 2013-12-07 04:46 -0500
        Re: Use of @Override when implementing interfaces v_borchert@despammed.com (Volker Borchert) - 2013-12-07 10:54 +0000
      Re: Use of @Override when implementing interfaces Fredrik Jonson <fredrik@jonson.org> - 2013-12-09 12:59 +0000
    Re: Use of @Override when implementing interfaces Arne Vajhøj <arne@vajhoej.dk> - 2013-12-09 21:06 -0500
      Re: Use of @Override when implementing interfaces "John B. Matthews" <nospam@nospam.invalid> - 2013-12-11 00:55 -0500

csiph-web