Swing generification changes in JDK 9 b24

Ben Evans benjamin.john.evans at gmail.com
Wed Jul 30 15:07:20 UTC 2014


Hi Joe,

Apologies if this has been explained elsewhere, but how does this fit
with the series of announcements that Swing is officially deprecated
and JavaFX is where it's at, as we've been hearing for a couple of
years now? If Swing really is a deprecated API, then why such a large
and potentially breaking change?

Thanks,

Ben



On Wed, Jul 30, 2014 at 3:54 PM, Joe Darcy <joe.darcy at oracle.com> wrote:
> 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:
>
> http://cr.openjdk.java.net/~darcy/OpenJdkDevGuide/OpenJdkDevelopersGuide.v0.777.html#general_evolution_policy
>
> 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 reconsidered.
>
> 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:
>
> http://mail.openjdk.java.net/pipermail/swing-dev/2014-June/003643.html
>
> "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
> :-)
>
> Thanks,
>
> -Joe


More information about the jdk9-dev mailing list