Re: Basic Syntax Question - String[].class

From: Raymond DeCampo (rdecampo_at_spam.twcny.spam.rr.spam.com.spam)
Date: 04/28/04


Date: Tue, 27 Apr 2004 23:50:59 GMT

Evil *** wrote:
> Hi,
>
> I'm building a Bison (LALR(1))-based java language parser, which is
> successfully building parse trees on 99.75% of the .java files in a test
> codebase.
>
> However, one construct which is derailing it is:
>
> Method m = cls.getMethod("main", new Class[] { String[].class; });
>
> The syntax error happens at the 'String [].class' in the array initializer.
>
> I'm still fairly new to Java, so from my limited understanding, 'String
> [].class' produces a Class object, being the class of array of String.
>
> I'm studying the language spec at:
>
> http://java.sun.com/docs/books/jls/first_edition/html/index.html
>
> but I'm failing to ascertain where 'String [].class' fits into the
> formal syntax description. What particular kind of syntactical entity is
> this?
>
> Can anyone point me to the right place in the syntax spec?
>
> Thanks in advance
> EB

First, "String[]" is an ArrayType. See section 19.4:

http://java.sun.com/docs/books/jls/first_edition/html/19.doc.html#26315

I can't seem to find where the ".class" notation is defined in the first
edition. Perhaps it did not exist in that edition.

It does appear in the second edition:

http://java.sun.com/docs/books/jls/second_edition/html/syntax.doc.html#44467

Look for the definition of "Primary".

HTH,
Ray