In order to return an immutable observable list to the clients of my API, I've used the FXCollections.unmodifiableObservableList(list) wrapper as follows:
private final ObservableList<Person> persons = FXCollections.observableArrayList();
public ObservableList<Person> getPersons() {
return FXCollections.unmodifiableObservableList(persons);
}
However, when a client adds a ListChangeListener to the returned list, it does not get notified when changes occur. This is apparently because the wrapper created by the FXCollections class sets a weak listener on the wrapped list, and this weak listener gets garbage collected.
Did I miss something about this wrapper?
What's the proper way to return an immutable observable list?