java - Can interface methods be overloaded? -


i'm trying achieve overloaded interface method. know not work in java, how rewrite following have implementation type in action() methods, , not base type?

class base; class foo extends base; class bar extends base;  interface iservice {    void action(base base); }  class fooservice implements iservice {    void action(foo foo) {      //executes specific foo action    } }  class barservice implements iservice {    void action(bar bar) {      //executes specific bar action    } } 

usage:

base base; //may foo or bar anyservice.action(bar); 

you idea. how this?

define interface both foo , bar should implement, can like:

interface actionable{     public void action; }  class base; class foo extends base implements actionable; class bar extends base implements actionable;  interface iservice {    void action(actionable a); }  class fooservice implements iservice {    void action(actionable a) {     ...    } }  class barservice implements iservice {    void action(actionable a) {     ...    } } 

anyway interfaces should make code more robust , reusable - if looking hacks make them work, consider designing application better.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -