Multiple interfaces with same method names [duplicate]
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.
精彩评论