Diamond operator and anonymous classes

Joe Darcy joe.darcy at oracle.com
Fri Jun 24 11:37:09 PDT 2011


Hello Derek,

First, thank you for relaying your experiences using the Coin features 
on actual code.  This is helpful input to possible future Coin 
refinements in JDK 8.

Derek Foster wrote:
> Hi, folks.
>
> I've been experimenting with applying the JDK 7 language additions to some code bases of mine, and anticipating such changes to my employer's code base at such time as we can upgrade to JDK 7. In most cases, this has gone quite well. However, I have run into one issue that has been rather annoying in some places. This has to do with the diamond operator.
>
> As originally proposed and reviewed on the Project Coin mailing list, the diamond operator could be used in both ordinary instance declarations, like:
>
>    private final List<Integer> foo = new ArrayList<>();
>
> and in anonymous class declarations such as:
>
>    public static final Callable<Integer> TASK = new Callable<>() {
>       public Integer call() {
>           return doSomething();
>       } 
>    };
>
> However, a later decision (by the Expert Group? or someone else?) declared that there were technical problems in implementing this for anonymous classes, and that support for using the diamond operator in anonymous classes would be dropped. (Unfortunately, I am unable to go review the expert group's discussions to determine what the detailed motivations were for making this change, since the expert group's discussions are apparently not public. I am a bit frustrated by the lack of visibility for this change and its motivations.)
>   

At the start of March, I posted "Project Coin Documentation v0.83" [1] 
and informed the coin-dev list of this document [2] (as well as blogged 
about it [3]); that document states in the discussion section for diamond:

"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."

and there is a further addendum

"(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.)"

As David Holmes has already quoted, there is a fuller discussion of 
diamond and anonymous inner class decision in the subsequent version of 
the Project Coin documentation [4] and Dan Smith has replied with more 
information about future evolution possibilities.

Since David and Dan have addressed the technical points, I'd like to to 
discuss the communications issues around Project Coin and JSR 334.

I understand that some people are frustrated that indications were made 
that the JSR 334 expert group archives were going to be public and, to 
date, they have not been.  While this is unfortunate,  I don't think 
this renders the decisions and progress of Project Coin impossible to 
follow.  Major expert group decisions have corresponding threads on 
coin-dev, e.g.:

* "Update on JSR 334 Expert Group activities," January 21, 2011
    http://mail.openjdk.java.net/pipermail/coin-dev/2011-January/002972.html

* "How to terminate resources in try-with-resources"
    http://mail.openjdk.java.net/pipermail/coin-dev/2011-January/003054.html

* "Specification update: diamond and explicit generic constructor 
argument no longer supported"
    http://mail.openjdk.java.net/pipermail/coin-dev/2011-May/003250.html

and discussions started on coin-dev have directly influenced the outcome 
of the JSR and the reference implementation, including but not limited to:

* diamond and raw types bug
    
http://mail.openjdk.java.net/pipermail/coin-dev/2011-February/003067.html

* null handling of try-with-resources
    http://mail.openjdk.java.net/pipermail/coin-dev/2011-January/002960.html
    
http://mail.openjdk.java.net/pipermail/coin-dev/2011-February/003076.html

I have striven to make the Project Coin documentation drops, and the 
similar materials posted for the JSR 334 milestones, stand-alone 
documents that contain the rationale for the changes.  From a quick 
scan, roughly one third of of the v0.9375 document is discussion as 
opposed to specification.

I have at times been disappointed in the coin-dev response to these 
documents and threads.  For example, for a full week after the v0.83 
document was posted, there was exactly zero response on coin-dev.  When 
prompted with a follow-up message seven days later, the primary reaction 
was on a minor syntax point.  No one is obliged to read these documents 
or respond to them.  However, in my own estimation there has not been a 
shortage of information made available about Coin and its progress over 
time in various venues and issues raised on coin-dev continue to be 
responded to promptly by myself and others.

-Joe

[1] 
http://cr.openjdk.java.net/~darcy/ProjectCoin/ProjectCoin-Documentation-v0.83.html
[2] http://mail.openjdk.java.net/pipermail/coin-dev/2011-March/003124.html
[3] http://blogs.oracle.com/darcy/entry/project_coin_developer_preview
[4] 
http://cr.openjdk.java.net/~darcy/ProjectCoin/ProjectCoin-Documentation-v0.9375.html




More information about the coin-dev mailing list