Java – monitor changes to collections

Suppose you have the following Java beans:

public class MyBean
{
    private List<String> names = new ArrayList<String>();

    public void addName(String name)
    {
        names.add(name);
        fireNamesPropertyChange(name);
    }
}

How do you usually implement property change events for collections? Do you try to use index properties, which seem to be more for arrays than collections?

Solution

Look at the glazed lists library, which supports observable collections

If I do this myself, I may create a custom listener interface that includes elementsadded, elementsremoved methods or similar: -) (also depending on my needs)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>