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

Comparator in TreeTableView has wrong generic type

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 8
    • javafx
    • jdk8 b115

    Description

      The default comparator in TreeTableView is a Comparator<TreeItem<S>>, not a Comparator<S> as indicated by the signature of the getComparator method. This causes the code below to fail with a ClassCastException:

          TreeTableView<Item> table = new TreeTableView<>(getRoot());
          table.comparatorProperty().addListener((ObservableValue<? extends Comparator<Item>> observable, Comparator<Item> oldValue, Comparator<Item> newValue) ->
              newValue.compare(new Item(0), new Item(1))
          );

      Workaround: getting rid of generics and explicitly casting to Comparator<TreeItem<Item>>.

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            ytallecjfx Yann Le Tallec (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: