Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override / Disable super-interface method

Tags:

java

interface

Consider the interfaces

public interface SuperInterface {

  public void execute(Map<String,object> argument);

}

public interface SubInterface extends SuperInterface {

  public void execute(Argument extra , Map<String,Object> args);

}

Is it possible to completely override SuperInterfaces.execute with SubInterface.execute even though it has different arguments ?

OR

Am I doing it wrong ? What is the right way to design this spec ?

like image 634
Gautam Avatar asked Feb 20 '26 21:02

Gautam


2 Answers

No. When you override a method, it must have the same number and types of arguments. Currently you are overloading the execute method in SubInterface.

You could, however, call execute(Map<String, Object> args) from execute(Argument extra , Map<String, Object> args) from your implementation of SubInterface.

like image 106
Reimeus Avatar answered Feb 24 '26 14:02

Reimeus


Is it possible to completely override SuperInterfaces.execute with SubInterface.execute even though it has different arguments ?

If you are allowed to do this, you will breach an agreement.

Am I doing it wrong ?

Yes, of course.

What is the right way to design this spec ?

You can't disobey an agreement. So, you can't do like this.

like image 35
Abimaran Kugathasan Avatar answered Feb 24 '26 14:02

Abimaran Kugathasan



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!