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: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: pushing the JLS envelope... (6.4.2. Obscuring) Date: Sat, 19 Oct 2013 02:49:57 +0200 Organization: A noiseless patient Spider Lines: 54 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 19 Oct 2013 00:50:02 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="14a9fa9ec43960cb7cd4b5677e637b09"; logging-data="20898"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mQ3sZCq+0Xkcrv9R6/e2i" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 In-Reply-To: Cancel-Lock: sha1:11OYfjbJqKW2IVeLnGoAXOM18ZI= Xref: csiph.com comp.lang.java.programmer:26377 On 2013-10-19 01:48, Andreas Leitgeb allegedly wrote: > Ok, I know that this breaks conventions and common sense, but > just for the sake of understanding the JLS... > > --- snip foo/Foo.java --- > package foo; > public class Foo { > public static String bad_name = "boo!"; // bad name for a field > public static class bad_name { // even worse, because lower case > public static void foo() { } > } > static { > bad_name.foo(); // doesn't work, because field obscures type - Ok. > foo.Foo.bad_name.foo(); // fqn doesn't work, either, but shouldn't it? > } > } > --- end snip --- > > JLS (6.4.2. Obscuring) has to say about this case: > - If a field name obscures a type name, then a > fully qualified name for the type can be used > unless the type name denotes a local class (§14.3). > ("bad_name" isn't a local class, so the "unless"-part doesn't apply.) > > Even if the field was non-static, the compiler still doesn't use > the type but rather complains about unavailability of the field, > even with the fqn. > > PS: suggesting "rename the field or (better) the type" as a solution > is really missing the point of this post. > The FQN is ambiguous. According to [6.5.2. Reclassification of Contextually Ambiguous Names]: >>>>>> If the name to the left of the "." is reclassified as a TypeName, then: If the Identifier is the name of a method or field of the type denoted by TypeName, this AmbiguousName is reclassified as an ExpressionName. *Otherwise*, if the Identifier is the name of a member type of the type denoted by TypeName, this AmbiguousName is reclassified as a TypeName. <<<<<< Ergo, foo.Foo.bad_name refers to foo's the member of type String, bad_name (great name btw.). ... At least that's how I'd interpret it. -- DF.