使用javafx属性克隆域对象

时间:2014-10-24 13:35:56

标签: java clone javafx-8

我在javafx应用程序中有一些域对象,我正在尝试使用Java deep cloning library进行克隆。如果我向其中一个javafx属性添加侦听器,则克隆将失败并显示NoClassDefFoundError。我试过告诉克隆者为侦听器类插入null而不是clone,但这没有任何影响:

com.rits.cloning.Cloner cloner = new com.rits.cloning.Cloner();
cloner.nullInsteadOfClone(ChangeListener.class, InvalidationListener.class);

有没有人有任何提示?

示例代码:

具有javafx属性的域对象:

public class ItemType implements Serializable {

private final LongProperty id;
private final StringProperty description;

public ItemType() {
    this.id = new SimpleLongProperty();
    this.description = new SimpleStringProperty();
}

public Long getId() {
    return this.id.get();
}

public void setId(Long id) {
    this.id.set(id);
}

public LongProperty idProperty() {
    return this.id;
}

public String getDescription() {
    return this.description.get();
}

public void setDescription(String description) {
    this.description.set(description);
}

public StringProperty descriptionProperty() {
    return this.description;
}

成功的代码:

ItemType itemtype = new ItemType(1L, "test");
cloner.deepClone(itemtype);

失败的代码:

ItemType itemtype = new ItemType(1L, "test");
itemtype.idProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable,
                Number oldValue, Number newValue) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

    });
cloner.deepClone(itemtype);

0 个答案:

没有答案