3

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) 
1
  • Interface with out a method is correct but your question is not clear. Commented Jan 22, 2013 at 9:59

3 Answers 3

2

yes it is correct. it is called Marker Interface.

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

Is it correct to extend a Class that has not other object in it?

I assume by this you mean an empty interface.

This is something that was used in Java a lot before they had annotations to sign a class is of that type ( from Java 5 ).

What you are doing is correct - basically you are marking the extended interfaces/classes type of EventClass but I would use annotation which is the new way to do that

http://tutorials.jenkov.com/java-reflection/annotations.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.