开发者

Multiple interfaces with same method names [duplicate]

This question already has answers here: Closed 12 years ago.

I have a class which inherits from two different interfaces. Both interfaces declar开发者_开发问答e a method with the same name. How can I provide a different implementation for each interface ?

In C#, the answer is there, but it does not work in java: Inheritance from multiple interfaces with the same method name

I thought about providing a union implementation which uses type comparison but it's kind of ugly.

Thanks

EDIT : closed, my question was a duplicate of the following, thank you for the answers ! Java - Method name collision in interface implementation


You can't. Interfaces describe behavior, but they don't implement it. So if you implement a method, there's no way to tell which interface you are implementing it from.


No, there's no equivalent feature in Java.

And you can't do it yourself, because inside the method, you have no way of telling if the calling code is referencing the object as InterfaceA or InterfaceB. Even if you could, I think it would be a bad idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜