tags:

views:

58

answers:

2

Hello,

I have a class which inherits from two different interfaces. Both interfaces declare 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: http://stackoverflow.com/questions/2371178/inheritance-from-multiple-interface-with-the-same-method-name-in-c

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 ! http://stackoverflow.com/questions/2598009/method-name-collision-in-interface-implementation-java

+1  A: 

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.

seanizer
A: 

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.

Mike Baranczak