Is there a Map implementation with listeners for Java?

前端 未结 4 1440
小鲜肉
小鲜肉 2021-02-19 14:01

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?

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 14:20

    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 implements Map {
    
        private final Map delegatee;
    
        public MapListener(Map delegatee) {
            this.delegatee = delegatee;
        }
    
        // implement all Map methods, with callbacks you need.
    
    }
    

提交回复
热议问题