Override what?

In my NPC interface I have:

public void move(int x, int y);

My Character class has this:

public class Character extends Component implements NPC

When I have Eclipse automatically add the unimplemented methods, it doesn’t add move(), so when I manually create it having @override, it tells me that I’m overriding the move method of Component. Is there a way to tell it that I’m overriding the NPC interface method and not the Component class?

Overriding is done by checking a method’s signature: Return type, name, method parameters. If your method matches that of a class that is being extended, then that method is overriden. In this case, the only thing you can do is provide another method signature (Change the name or parameters), otherwise you will always be overriding the things in Component.

With Interfaces, you’re not overriding anything. You’re implementing it. Which is two different ideas. Overriding is hiding another method declaration with yours. Implementing is ensuring that the contract described by the Interface or by an abstract class is met. In this case, Component is providing the implemenation of void move(int x, inty), which is why it doesn’t show up when you add unimplemented methods.

First of all, an entity should not be an AWT Component…

In the end, you should either rename that method or not use Component.

It needs to have Component so i can use createImage(), and didn’t want to rename some of the methods, but that’s what I’ll do.

Overriding Component just to get createImage is insane. Pass in an ImageCreator to the constructor instead. Or pass it in to the method that needs to create the image. Do anything but override Component.

This whole time I was passing ‘this’ to it, saving it as ‘that’. I never knew I could use that.createImage(). Thank you for the pointer.