扩展空接口是否正确?我只需要一个带有参数(EventCLass myEvent)的方法(EventPlayer),该方法可以是一次类,下一次是另一个类。
public interface EventClass {
// ... empty ...
}
public interface EventClassExt1 extends EventClass {
public void firstEvent();
public void secondEvent();
}
public interface EventClassExt2 extends EventClass {
public void thirdEvent(String text);
}
public EventPlayer(final EventCLass myEvent)
答案 0 :(得分:2)
是的,这是正确的。它被称为标记接口。
答案 1 :(得分:2)
是的,可以这样做。
当接口没有方法时,通常称为marker interface; Serializable
是JDK中此类接口的众多示例之一。
另外,您可能不希望在接口名称中使用“class”。只需Event
就是更好的选择。
答案 2 :(得分:1)
扩展一个没有其他对象的类是否正确?
我认为你的意思是一个空的界面。
这是Java在用于签署类的注释之前在Java中使用的东西(来自Java 5)。
你正在做的是正确的 - 基本上你正在标记EventClass
的扩展接口/类类型,但我会使用注释,这是新的方法
http://tutorials.jenkov.com/java-reflection/annotations.html