是否有一个带有Java侦听器的Map实现? [英] Is there a Map implementation with listeners for Java?

查看:93
本文介绍了是否有一个带有Java侦听器的Map实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个Map实现,我可以在其中添加put()事件的监听器。

I would like a Map implementation in which i could add listeners for put() events.

标准或任何第三方库中是否有类似内容?

Is there anything like that in the standard or any 3rd party libraries?

推荐答案

我不知道任何标准或第三方,但它很容易,只需创建一个包装另一个Map的类并实现Map接口:

I'm not aware of any standard or 3rd party, but it is easy, just create a class which wraps another Map and implements the Map interface:

public class MapListener<K, V> implements Map<K, V> {

    private final Map<K, V> delegatee;

    public MapListener(Map<K, V> delegatee) {
        this.delegatee = delegatee;
    }

    // implement all Map methods, with callbacks you need.

}

这篇关于是否有一个带有Java侦听器的Map实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆