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.

Marlord
  • 1,144
  • 2
  • 13
  • 24
  • My guess is that getValue() returns a `double` and `get` returns a `Double`. What does the Javadoc say? – Peter Lawrey Jun 04 '14 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 04 '14 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. – Peter Lawrey Jun 04 '14 at 16:37
  • 1
    Related: [SimpleStringProperty set() vs. setValue()](http://stackoverflow.com/questions/16234669/simplestringproperty-set-vs-setvalue) – jewelsea Jun 04 '14 at 16:58

1 Answers1

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();
}
Jacob Lockard
  • 1,195
  • 9
  • 24
Jens
  • 67,715
  • 15
  • 98
  • 113
  • 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 04 '14 at 16:40
  • Then the methode you define will be called. – Jens Jun 04 '14 at 16:42