JavaFX bean是否需要可序列化?

时间:2020-10-25 21:01:06

标签: javafx

许多JavaFX constructors,例如SimpleStringProperty,指定第一个参数应该是bean。我知道JavaBean的特质之一是SerializableThe Definitive Guide to Modern Java Clients with JavaFX中的示例代码具有examples,其中在bean位置传递的参数不可序列化:

public class Person { // not Serializable
    private final StringProperty firstname = new SimpleStringProperty(this, "fistname", "");
    private final StringProperty lastname = new SimpleStringProperty(this, "lastname", "");
    private final StringProperty notes = new SimpleStringProperty(this, "notes", "sample notes");

JavaFX bean是否需要为Serializable或仅具有公共无参数构造函数和设置器/获取器才能访问私有字段?

1 个答案:

答案 0 :(得分:0)

除非您打算在该类或任何子类上使用序列化,否则并非强制类为Serializable