According to
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.9
the following production holds
<ClassInstanceCreationExpression> ::=
"new" [<TypeArguments>] <ClassOrInterfaceType> "(" [<ArgumentList>] ")"
What would be an example for a class instance creation expression
with type arguments? Here's a reminder about those:
<TypeArguments> ::=
"<" <TypeArgument> {"," <TypeArgument>} ">"
What I would understand would be:
<ClassInstanceCreationExpression> ::=
"new" <ClassOrInterfaceType> [<TypeArguments>] "(" [<ArgumentList>] ")"
Stefan Ram - 03 Dec 2005 18:59 GMT
>What I would understand would be:
><ClassInstanceCreationExpression> ::=
>"new" <ClassOrInterfaceType> [<TypeArguments>] "(" [<ArgumentList>] ")"
OK, this does not make sense, because "<TypeArguments>"
already are part of "<ClassOrInterfaceType>" -- so what I
understand would be:
"new" <ClassOrInterfaceType> "(" [<ArgumentList>] ")"
Chris Smith - 03 Dec 2005 19:35 GMT
> >What I would understand would be:
> ><ClassInstanceCreationExpression> ::=
[quoted text clipped - 5 lines]
>
> "new" <ClassOrInterfaceType> "(" [<ArgumentList>] ")"
Does this help?
public class Test<T>
{
public <E> Test()
{
}
public static void main(String[] args)
{
Test<String> t = new <Number> Test<String>();
}
}
In the line of code in main, "<Number>" matches the TypeArguments in the
production for ClassInstanceCreationExpression. <String> matches the
TypeArguments for ClassOrInterfaceType. The former is a set of explicit
type arguments on the constructor, not the class.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Stefan Ram - 03 Dec 2005 19:53 GMT
>public class Test<T>
>{
[quoted text clipped - 8 lines]
>}
>Does this help?
Yes. So, "Number" is the argument for the constructor's type
parameter "E". I believe that I was able to grasp the
formalism, though I would still will have to sit down and
think about it in order to find an example where such a
parameter is helpful.
Hendrik Maryns - 05 Dec 2005 12:52 GMT
Stefan Ram schreef:
>>public class Test<T>
>>{
[quoted text clipped - 14 lines]
> think about it in order to find an example where such a
> parameter is helpful.
I seem to recall to have seen something like this in the source code of
HashMap. Anyway, the same can be done when invoking methods against an
object/a class, and unfortunately you really need it, as in:
public class SomeClass{
public void someMethod(Set<String>){}
}
public class Main{
public static void main(String[] args){
someMethod(Collections.<String>emptySet())
}
}
You really need the <String> there, otherwise the compiler will complain
method is not applicable to the arguments Set<Object>.
See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6293352
HTH, H.

Signature
Hendrik Maryns
==================
www.lieverleven.be
http://aouw.org
Thomas Hawtin - 03 Dec 2005 19:39 GMT
> According to
>
[quoted text clipped - 15 lines]
> <ClassInstanceCreationExpression> ::=
> "new" <ClassOrInterfaceType> [<TypeArguments>] "(" [<ArgumentList>] ")"
It's the same as the type arguments before a method. I can't quite think
why you would want it. Potentially you might want two arguments, say,
Comparable, but in a constructor?
new <String>MyClass(strListA, strListB)
public <T> MyClass(List<T> a, List<T> b) { ... }
Looks unlikely to me. Almost certainly you could use wildcard instead.
There appears to be a slight error in the stated grammar. javac does not
accept wildcard types there. They wouldn't make any sense in that position.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/