Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8186187

Modify return type of public API StyleConverter.getEnumConverter()

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE REQUEST :
      StyleConverter.getEnumConverter() returns an instance of converting in "StyleConverter<String,? extends Enum<?>>" type, whereas constructor of CssMetaData expects "StyleConverter<?, V>" where V is the type of the enum.

      This forces the developer to cast the converter returned from StyleConverter.getEnumConverter() method, which would generate an unchecked cast warning.

      This causes the following code to have compile-time error:
      public static final CssMetaData<MyNode, MyEnum> MY_ENUM = new CssMetaData<MyNode, MyEnum>(
      "-my-enum",
      StyleConverter.getEnumConverter(MyEnum.class),
      MyEnum.TEST);

      This gave the following compile-time error:
      The constructor CssMetaData<MyNode,MyEnum>(String, StyleConverter<String,capture#1-of ? extends Enum<?>>, MyEnum) is undefined.

      Looking at JavaFX 9 documentation, it seems like this method remains defined this way.

      JUSTIFICATION :
      Since javafx.css.StyleConverter class is intended to make CSS styling API public (from the original private API), it should have complete compatibility with the other classes/methods that are made public along with it. Therefore I would recommend that StyleConverter.getEnumConverter() returns "StyleConverter<String,? extends E>", unless doing so would break the API somewhere else.

      I believe there is nothing wrong in changing the method definition to "public static <E extends Enum<E>> StyleConverter<String,E> getEnumConverter€‹(Class<E> enumClass)".

      CUSTOMER SUBMITTED WORKAROUND :
      The current workaround is to do an unchecked cast for the StyleConverter, which will create a warning unless I suppressed it.


            pkbalakr Prem Balakrishnan (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: