Re: Java 2.0 Grammar Problems

Thomas Maslen <>
17 Feb 2001 01:32:52 -0500

          From comp.compilers

Related articles
Java 2.0 Grammar Problems (Michael Schoettner) (2001-02-12)
Re: Java 2.0 Grammar Problems (Kees van Reeuwijk) (2001-02-15)
Re: Java 2.0 Grammar Problems (Thomas Maslen) (2001-02-17)
Re: Java 2.0 Grammar Problems (Kees van Reeuwijk) (2001-02-23)
Re: Java 2.0 Grammar Problems (Peter Bertelsen) (2001-02-25)
Re: Java 2.0 Grammar Problems (2001-03-01)
| List of all articles for this month |

From: Thomas Maslen <>
Newsgroups: comp.compilers
Date: 17 Feb 2001 01:32:52 -0500
Organization: Distributed Systems Technology CRC
References: 01-02-040
Keywords: Java, parse
Posted-Date: 17 Feb 2001 01:32:52 EST

"Michael Schoettner" <> writes:
> ( Expression )
> this [Arguments]
> super SuperSuffix
> Literal
> new Creator
> Identifier { . Identifier }[ IdentifierSuffix]
> BasicType BracketsOpt .class (*)
> void.class (**)
>(*) + (**) What are these productions good for?

They name Class instances that represent the primitive types (int, boolean,
float etcetera) and arrays thereof, and also void. These are used with
reflective methods such as

java.lang.Class.getDeclaredMethod(String, Class[])

although void.class probably only occurs as the return value of


Class literals (anything with ".class") are syntactic sugar which the
compiler maps to other constructs:

void.class java.lang.Void.TYPE

int.class java.lang.Integer.TYPE

int[][][].class Class.forName("[[[I")

Foo.class Class.forName("")

Foo[][][].class Class.forName("[[[;")

In practice the call to Class.forName() is done once and then cached in a
static field, and ClassNotFoundException is mapped to NoClassDefFoundError.

You could argue that int.class et al and void.class are unnecessary,
since you can just as well write Integer.TYPE and Void.TYPE, but overall
I'm glad that the ".class" sugar exists because, unlike Class.forName(),
it can be checked at compile time.

Thomas Maslen

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.