Is there a Map implementation with listeners for Java?

前端 未结 4 1441
小鲜肉
小鲜肉 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条回答
  •  -上瘾入骨i
    2021-02-19 14:23

    What you are essentially asking for is a Cache which can provide event notification. There are some products out there like Infinispan that already provide that for you but without knowing your use case its hard to recommend.

    If you want a simple ObservableMap it should be easy to implement. You simply have to create an Observer pattern. You can find an example here.

提交回复
热议问题