Implementing Generic Interface in Java

后端 未结 7 2046
忘了有多久
忘了有多久 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:04

    No, because different "concrete" generic types in Java compile to the same type. The actual interface your object will implement is:

    public interface Handles {
        public void handle(Event event);
    }
    

    And, obviously, you can't have two different methods with an identical signature...

提交回复
热议问题