Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleStringProperty set() vs. setValue()

Tags:

What is the difference between set(String) and setValue(String) in the SimpleStringProperty class?

I know that set(String) is derived from StringPropertyBase, but this makes me even more wonder, why there additionally is setValue(String)?

like image 335
stefan.at.wpf Avatar asked Apr 26 '13 10:04

stefan.at.wpf


1 Answers

set/setValue and get/getValue methods pairs exist to align Object properties with primitive types properties like BooleanProperty or DoubleProperty:

BooleanProperty:

void set(boolean value)
void setValue(java.lang.Boolean v)

DoubleProperty:

void set(double value)
void setValue(java.lang.Number v)

In these property classes ___Value methods work with corresponding to type objects while direct methods work with primitive types.

Looking in the code you may find a bit of a difference in the logic. For example, DoubleProperty#setValue(null) is equal to DoubleProperty#set(0.0) (which was required by binding). So generally I'd advise to use set/get methods and leave setValue/getValue to binding needs as they may incorporate additional logic.

For Object/String properties there is no difference between set and setValue methods.

like image 167
Sergey Grinev Avatar answered Oct 28 '22 09:10

Sergey Grinev