Swing generification changes in JDK 9 b24

Joe Darcy joe.darcy at oracle.com
Wed Jul 30 14:54:50 UTC 2014

Hi Andrej and Martijn,

Thanks for responding.

On 7/28/2014 5:04 AM, Andrej Golovnin wrote:
> Hi Joe,
> I'm not sure if it is what you are looking for.

For context, the general evolution policy of the JDK:


includes "avoid introducing source incompatibilities." As this is a 
large generification change to swing, some level of source 
incompatibility may be acceptable in a platform release like JDK 9, but 
if there are very widespread issues, some of the changes may be 

The request to try out the changes was to get enough information to see 
if any (partial) reconsideration was warranted.

> But I tried to compile my project with the new build. And I got a 
> compile error in one of my classes. I have a class which implements 
> the TreeNode interface and looks like this:
> class MyTreeNode implements TreeNode {
> ....
>     @Override
>     public Enumeration<MyTreeNode> children() {
>         return ....;
>     }
> ...
> }
> The error message is: "return type Enumeration<MyTreeNode> is not 
> compatible with Enumeration<TreeNode>".
> If I change (see attached patch) the definition of the 
> children()-method in the TreeNode-interface to:
> public interface TreeNode {
> ...
>     Enumeration<? extends TreeNode> children();
> ...
> }
> then my code compiles.

That design issue was raised during code review:


"It was not immediately clear how javax.swing.tree.TreeNode.children(),
which returns a raw Enumeration, should be generified. I changed it to

      Enumeration<TreeNode> children();

and that seems to work fine. Something like

      Enumeration<? extends TreeNode>

with a covariant override would save a few casts in a private
implementation, but generally doesn't seem to be a good trade-off since
many normal clients could be inconvenienced dealing with the wildcard."

If generified subclasses of TreeNode are common, the generification of 
children may need reconsideration.

> BTW, a good test for your changes would be to try to compile NetBeans 
> and/or IntelliJ IDEA using the new JDK 9 build. They both are really 
> big Swing applications which make use maybe of all Swing APIs.

My preference would be for the NetBeans and IntelliJ teams to do that 
task :-)



More information about the jdk9-dev mailing list