I have an interface like the following:
package example;
import java.awt.Point;
public interface Thing {
public enum MovingState {
MOVING_LEFT,
MOVING_UP,
MOVING_RIGHT,
MOVING_DOWN
}
public void setNewPosition(MovingState state);
public Point getPosition();
}
and an implementation class:
package example;
import java.awt.Point;
public class ThingImpl implements Thing {
public enum MovingState {
MOVING_LEFT (-1, 0),
MOVING_UP (0, -1),
MOVING_RIGHT (1, 0),
MOVING_DOWN (0, 1);
private int x_move;
private int y_move;
MovingState(int x, int y) {
x_move = x;
y_move = y;
}
public int xMove() {
return x_move;
}
public int yMove() {
return y_move;
}
}
private Point position;
public void setNewPosition(MovingState state) {
position.translate(state.xMove(), state.yMove());
}
public Point getPosition() {
return position;
}
}
The idea is to have MovingState
in ThingImpl
extend MovingState
from the Thing
interface (thus separating the actual implementation of MovingState
from the interface).
This doesn't work though - the MovingState
enum in ThingImpl
shadows the definition in the interface instead of extending it, then the compiler complains that ThingImpl is not abstract and does not override abstract method setNewPosition(Thing.MovingState) in Thing.
Is there an actual way to do what I'm trying to achieve? Or does Java simply not have this capability?