Bug 87761 - [1.5][compiler] Nested parameter types for class directive
Summary: [1.5][compiler] Nested parameter types for class directive
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-11 08:05 EST by Martin Kersten CLA
Modified: 2005-03-11 12:25 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Kersten CLA 2005-03-11 08:05:30 EST
I am using Eclipse 3.1 M4 and I get a parser error which shouldn't occure in my
oppinion.

Version A:

01: Mock<List<TreeItem>> itemListMock;
02: itemListMock=createMock(List<TreeItem>.class);

Version B:

01: Mock<List<TreeItem>> itemListMock;
02: Class<List<TreeItem>> clazz=(Class<List<TreeItem>>)List.class;
03: itemListMock=createMock(clazz);
                                     
Using version A, I get the "Syntax error on token '>', void expected after this
token" message right about the character '>' in the line 02. I guess it should
be valid to state List<Type>.class since I can cast Class<List> to
Class<List<TreeItem>> like seen in line 02 of version B.

List<TreeItem>.class does not work also. So I guess there is some issue within
the parser or the Java folks made an unnessary inconsitency.


Cheers,

Martin (Kersten)
Comment 1 Olivier Thomann CLA 2005-03-11 11:31:16 EST
It seems that class literals with generic types are illegal.
See comment in:
http://forum.java.sun.com/thread.jspa?forumID=316&threadID=519798

In fact this would collide with the relational expression a < b. Where a and b
are names.
Comment 2 Olivier Thomann CLA 2005-03-11 11:37:38 EST
From the JLS:

15.8.2 Class Literals
A class literal is an expression consisting of the name of a class, interface,
array, or primitive type, or the pseudo-type void, followed by a ‘.’ and the
token class.
The type of a class literal, C.Class, where C is the name of a class, interface
or array type, is Class<C>. If p is the name of a primitive type, let B be the
type of an expression of type p after boxing conversion (§5.1.7). Then the type
of p.class is Class<B>. The type of void.class is Class<Void>.

This states that only Name are legal as the left hand side of a class literal.
Note that javac also rejects such code.

So this is not consistent with the rule:
     Type . class
also found in the JLS. See 15.8 Primary Expressions.

Closing as INVALID.
Comment 3 Martin Kersten CLA 2005-03-11 12:25:32 EST
Thanks for investigating this issue. I will rework my test case to get rid of
the unsafe warning.

Thanks for your quick action,


Cheers,

Martin (Kersten)