Way to specify multiple interfaces in Java

后端 未结 6 813
清酒与你
清酒与你 2020-12-29 10:04

I have two interfaces, HasClickHandlers and DoesFancyFeedback. Then I have some UI objects that implement both interfaces - for example, a B

6条回答
  •  执念已碎
    2020-12-29 10:37

    No, there is no such a thing in Java.

    You would have to use the option you mention of creating a third interface. That way you'll be explicitly declaring your intention to use a new type.

    Is not that verbose after all ( considering the alternative ), because you would just type:

    public interface FancyWithHandler 
           extends HashClickHandlers , DoesFancyFeedback {} 
    

    You don't need to include the methods. And then just use it:

    FancyWithHandler clickyFeedbackThing = aThingIPassedIn;
    clickyFeedbackThing.addClickHandler();
    clickyFeedbackThing.doFancyFeedback();     
    

    While the generic option looks interesting, probably at the end you'll end up creating a much more verbose thing.

提交回复
热议问题