本文介绍了SimpleStringProperty set()与setValue()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

班级?

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

我知道 set(String)派生自,但这让我更加奇怪,为什么还有 setValue(String)

推荐答案

set / setValue get / getValue 存在方法对以使对象属性与原始类型属性,如 BooleanProperty DoubleProperty

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

BooleanProperty :

BooleanProperty:

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

DoubleProperty:

DoubleProperty:

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

In这些属性类 ___ Value 方法在指导我的同时使用对应的类型对​​象thods使用原始类型。

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

查看代码,您可能会发现逻辑上有点不同。例如, DoubleProperty #setValue(null)等于 DoubleProperty #set(0.0)(这是绑定所需的) )。所以我一般建议使用set / get方法并将setValue / getValue留给绑定需求,因为它们可能包含额外的逻辑。

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.

对于Object / String属性,没有set和setValue方法之间的区别。

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

这篇关于SimpleStringProperty set()与setValue()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 17:31