Diamond operator no longer working... ?

joe.darcy at oracle.com joe.darcy at oracle.com
Fri Mar 18 19:08:06 UTC 2011

On 3/18/2011 10:01 AM, assembling signals wrote:
> Hello, community!
> I noticed a new error since b134: "Cannot use '<>' with anonymous inner classes".
> The code uses diamond syntax and was error-free before b134.
> (Please see reproducible example at the end.)
> Can someone explain: is this error even intended?
> If so, why this is necessary? If not, is it possible to revert to old behavior?
> (BTW: Latest Netbeans even allow to refactor anon-inner-classes to use diamond syntax.)
> Best regards,
> Ivan G Shevchenko

As described in the recently published Project Coin documentation for 
the developer preview [1], using diamond with anonymous inner class is 
specifically disallowed:

> It is a compile-time error if a class instance creation expression 
> declares an anonymous class but uses "<>" in place of a class type 
> argument list.

It is noted in the document that

> (Note that javac in the JDK 7 developer preview erroneously accepts 
> diamond combined with non-generic classes and accepts some uses of 
> diamond with anonymous inner classes. These bugs will be corrected in 
> future builds.)

The future has arrived in b134 :-)

The discussion section of the feature has a brief rationale for this change:

> Using diamond with anonymous inner classes is /not/ supported since 
> doing so in general would require extensions to the class file 
> signature attribute to represent non-denotable types, a de facto JVM 
> change.

The public review draft of JSR 334 will have a more in-depth discussion.




More information about the core-libs-dev mailing list