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

Code example in JavaDoc of ObservableValue#when doesn't compile

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx23
    • jfx21
    • javafx
    • b03
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The code example in the JavaDoc of the method ObservableValue#when doesn't compile. The code example is reproduced below. None of the calls to the method setValue compile. The problem is that the variables `condition` and `longLivedProperty` are declared with the type ObservableValue, which doesn't have a `setValue` method. They should be of type `Property`. Or their declaration should use a `var`, like it's done for similar variables in code examples in the JavaDoc of the methods `map` and `orElse`.

      ```
           ObservableValue<Boolean> condition = new SimpleBooleanProperty(true);
           ObservableValue<String> longLivedProperty = new SimpleStringProperty("A");
           ObservableValue<String> whenProperty = longLivedProperty.when(condition);

           // observe whenProperty, which will in turn observe longLivedProperty
           whenProperty.addListener((ov, old, current) -> System.out.println(current));

           longLivedProperty.setValue("B"); // "B" is printed

           condition.setValue(false);

           // After condition becomes false, whenProperty stops observing longLivedProperty; condition
           // and whenProperty may now be eligible for GC despite being observed by the ChangeListener

           longLivedProperty.setValue("C"); // nothing is printed
           longLivedProperty.setValue("D"); // nothing is printed

           condition.setValue(true); // longLivedProperty is observed again, and "D" is printed
      ```



            jhendrikx John Hendrikx
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: