Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About Java subinterface subtype

Tags:

java

interface

This seems a basic java question.

I have one interface, Pipeline, which has a method execute(Stage).

Then I create a sub interface to extend from Pipeline, say BookPipeline, I like the method to be execute(BookStage).

BookStage extends from Stage.

Seems this kind of definition could not pass java compile.

Any suggestion on that?

like image 680
BlueDolphin Avatar asked May 04 '12 16:05

BlueDolphin


1 Answers

You may want to consider using generics.

public interface Pipeline<T extends Stage> {
     public void execute(T stage);
}

public interface BookPipeline extends Pipeline<BookStage> {
     @Override
     public void execute(BookStage stage);
}
like image 81
Jeffrey Avatar answered Oct 04 '22 21:10

Jeffrey