Why can't I implement multiple interfaces?

So what I don't understand is that both AnimatesPaint and AnimatesPosition already implement createAnimator.

Yes, and those implementations conflict with one another. If you could do this, your resulting class's type would need to expose two createAnimator methods that are only differentiated by return type. Java doesn't let you have overloads that are only differentiated by return type, so you can't do that. A method signature, for overloading purposes, doesn't include the return type.

Even if they had the same return type (Animator), you'd then have two overloads with exactly the same signature, which you can't do.

They'll need to be separate methods — e.g., with separate signatures that can be differentiated — if they're going to be implemented in the same class.


In a comment you've asked:

But isn't the conflict resolved by the fact that the method has already been overriden by AnimatesPaint and AnimatesPosition? This way the implementing class ScreenElement doesn't need to implement createAnimator method, so no conflict will occur.

No, because the class itself exposes those methods (or rather, would need to) as part of its signature. Basically, suppose you could create the class and you had an instance of it, s. What would s.createAnimator(300L) do? Which one should the compiler choose?

A class's public type is composed of all of its public members, including all the public members of all of the interfaces it implements. So at a type level, it's impossible for two interfaces to implement methods with the same signature.


If you call ScreenElements createAnimator() method, which one is it supposed to use? That’s what the compiler is complaining about. You need to tell it what to do when that method is called. Based on the code I’m not sure. So you are correct that ScreenElement needs to implement the create animator method, that way the compiler knows what to do when that method is called.