Implementing multiple generic interfaces

后端 未结 2 1989
粉色の甜心
粉色の甜心 2021-01-19 01:07

I need to handle events of two different types but I\'m running into the following issue:

The interface EventListener cannot be implemented more than once with diffe

2条回答
  •  星月不相逢
    2021-01-19 01:51

    There is only one handle(Object) method in reality. You are effectively write the same as

    public class CompositeListener implements EventListener {
        public void handle(Object event) {
            if (event instanceof PriceUpdate) {
                ///
            } else if (event instanceof OrderEvent) {
                ///
            }
        }
    }
    

    Without this checking logic, you can't effectively call your event listener in any case.

提交回复
热议问题