6

I had this listing and i can't see what is the porpouse:

DoubleProperty value = new DoublePropertyBase(0) {
        @Override protected void invalidated() {
            if (getValue() < get()) setValue(get());
        }
        @Override public String getName() { return "value"; }
    };

Is like getValue() is the new Value and get() is the old, but the documentation does not say that.

4
  • My guess is that getValue() returns a double and get returns a Double. What does the Javadoc say? Jun 4, 2014 at 16:22
  • 1
    The value can be manipulated with the get(), set(), getValue(), and setValue() methods. The get() and set() methods perform their operation with the primitive int type. The getValue() and setValue() methods use the Integer wrapper type.
    – Marlord
    Jun 4, 2014 at 16:30
  • My guess was half right. So now you know the difference. One could create an object and the other doesn't use an object. Jun 4, 2014 at 16:37
  • 1
    Related: SimpleStringProperty set() vs. setValue()
    – jewelsea
    Jun 4, 2014 at 16:58

1 Answer 1

7

If you look at the source code of the superclass of DoubleProperty you can see that both methods return the same value. get() returns the primitive type double and getValue() a Double object.

javafx.beans.binding.DoubleExpression

@Override
public Double getValue() {
    return get();
}

javafx.beans.property.ReadOnlyDoubleProperty

@Override
public double get() {
    valid = true;
    final T value = property.getValue();
    return value == null ? 0.0 : value.doubleValue();
}
2
  • And if exist a method with the same name in the class where is the property, wich method is called? DoubleProperty value = new DoublePropertyBase(0) {...} getValue(){...}
    – Marlord
    Jun 4, 2014 at 16:40
  • Then the methode you define will be called.
    – Jens
    Jun 4, 2014 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.