我想创建一个几乎与返回的对象相同FXCollections.observableArrayList()但具有一些额外功能的类.我的第一个想法就像是
public class MyObservableList implements ObservableList
{
private ObservableList list = FXCollections.observableArrayList();
public functionWhatever()
{
// whatever
}
}
Run Code Online (Sandbox Code Playgroud)
但这意味着要覆盖所带来的~30个功能ObservableList(这似乎暗示我做错了什么).
FXCollections.observableArrayList()返回一个类型的对象com.sun.javafx.collections.ObservableListWrapper,但是当我扩展时,ObservableListWrapper我需要创建一个类似的构造函数
MyObservableList( List arg0 )
Run Code Online (Sandbox Code Playgroud)
要么
MyObservableList( List arg0, Callback arg1 )
Run Code Online (Sandbox Code Playgroud)
这让我担心,因为FXCollections.observableArrayList()不接受任何争论.
我不知道如何FXCollections创建ObservableListWrapper它返回的对象,但我希望MyObservableList与返回的对象相同FXCollections(加上一些额外的函数).
我该怎么做呢?
扩展SimpleListProperty docs.oracle.com
此类提供了包装 ObservableList 的 Property 的完整实现。
注意这位演员:
公共 SimpleListProperty(ObservableList 初始值)
所以你可以:
public class MyObservableList extends SimpleListProperty
{
//constructor
MyObservableList(){
super(FXCollections.observableArrayList());
}
public functionWhatever()
{
// whatever
}
}
Run Code Online (Sandbox Code Playgroud)
这样你的类将基于 ArrayList。