Implementing Generic Interface in Java

后端 未结 7 2012
忘了有多久
忘了有多久 2020-12-24 12:38

I have a Java generics question I was hoping someone could answer. Consider the following code:

public interface Event{}
public class AddressChanged implemen         


        
7条回答
  •  温柔的废话
    2020-12-24 13:01

    Unfortunately not. The usual solution (fat, ugly, fast) is to create one Handles interface (i.e. HandlesAddressChange, HandlesAddressDiscarded) and give each of them a different method (handleAddressChange(...), handleAddressDiscarded()).

    That way, the Java runtime can tell them apart.

    Or you can use anonymous classes.

提交回复
热议问题