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!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: the true literal Date: Thu, 21 Nov 2013 23:23:59 -0500 Organization: A noiseless patient Spider Lines: 75 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 22 Nov 2013 04:24:44 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="6b9e92482af47766954d85fb77d372f5"; logging-data="16440"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jSABIW5Kb8nFnRSALigUbvG7/pK+Jmss=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130922 Icedove/17.0.9 In-Reply-To: Cancel-Lock: sha1:i89rNENLjWXpOX94f5dW/+Vyiko= Xref: csiph.com comp.lang.java.programmer:26566 On 11/21/2013 09:24 PM, Stefan Ram wrote: > The JLS says: > > »While true and false might appear to be keywords, > they are technically Boolean literals (§3.10.3).« > > What is a keyword? > > I used to think that a keyword is a word(s) You'll need to adjust your intuition. ------------------------------------------------------------- > whose meaning is given by the language specification 3.10.3. Boolean Literals The boolean type has two values, represented by the boolean literals true and false, formed from ASCII letters. BooleanLiteral: one of true false A boolean literal is always of type boolean (§4.2.5). ------------------------------------------------------------ > and that cannot be declared as an identifier in source code. 3.8. Identifiers An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. Identifier: IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral ---------------------------------------------------------------- > I believe that all of this applies to »true«. The meaning of true is given in the JLS. A BooleanLiteral cannot be used as an Identifier. ------------------------------------------------------------ > So, why then it is not called a keyword in Java? 3.9. Keywords 50 character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (§3.8). Keyword: one of abstract continue for new switch assert default if package synchronized boolean do goto private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const float native super while Because it is a boolean literal? boolean t_; if ( !t_ ) t_ = true;