Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Is You Is Or Is You Ain't A Literal? Date: Wed, 5 Oct 2016 20:21:25 -0400 Organization: Aioe.org NNTP Server Lines: 43 Message-ID: References: NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:35730 On 10/5/2016 5:30 PM, Stefan Ram wrote: > Is »2« a literal? > > I think JLS 3.10.1 says "yes". > > But there also is a test method: > > javax.lang.model > > Enum SourceVersion > > public static boolean isKeyword( java.lang.CharSequence s ) > > Returns whether or not s is a keyword or literal in the latest > source version. > > Parameters: s - the string to check > > Returns: true if s is a keyword or literal, false otherwise. > > So, > > public final class Main > { public static void main( final java.lang.String args[] ) > { java.lang.System.out.println > ( javax.lang.model.SourceVersion.isKeyword( "2" )); }} > > false > > So, »2« is not a literal? 2 is a literal. The documentation is bad/misleading. A quick glance in the source code reveals what "or literal" means. It is only the 3 "name like" literals: null, true and false. Arne