Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - extend an interface

Is it correct to extend an empty interface? I just need to have a method (EventPlayer) with a parameter (EventCLass myEvent) that could be one time a class and the next time another class.

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) 
like image 586
Lorenzo Sciuto Avatar asked Nov 19 '25 16:11

Lorenzo Sciuto


2 Answers

yes it is correct. it is called Marker Interface.

http://en.wikipedia.org/wiki/Marker_interface_pattern

like image 116
Kent Avatar answered Nov 22 '25 06:11

Kent


Yes it's OK to do that.

When an interface has no methods, it's generally called a marker interface; Serializable is one of many examples of such an interface from the JDK.

Also, you probably don't want "class" in your interface name. Just Event is a better choice.

like image 37
Bohemian Avatar answered Nov 22 '25 05:11

Bohemian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!