Community
Participate
Working Groups
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)
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.
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.
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)