I have a generic game class called RiverCrossingGame
. The idea is that subclasses of this one will implement different river crossing puzzles.
In my superclass I have a Vector
of states. Now these states are generic. The GenericState
implements some behavior common in the concept of state for any river crossing game. The the subclass associated State will implement additional methods which are particular of the game.
So I have my RiverCrossingGame
with the vector of states:
public abstract class RiverCrossingGame implements PuzzleGame {
public GenericBank westBank;
public GenericBank eastBank;
public static Vector<GenericState> states;
public List<String> steps;
public abstract void play();
public abstract void printSteps();
}
Then the WolfGoatCabbageGame
I have defined a particular state for this game called State
(it is in the Wolf, Goat and Cabbage game package) which is a subclass of the GenericState
:
public class State extends GenericState {
// State members...
}
Then in the class for the actual class I try to initialize the vector of states:
public class WolfGoatCabbageGame extends RiverCrossingGame {
public enum Element { FARMER, WOLF, GOAT, CABBAGE };
public WolfGoatCabbageGame() {
westBank = new Bank("WEST", new Element[]{ Element.FARMER, Element.WOLF, Element.GOAT, Element.CABBAGE }, false);
eastBank = new Bank("EAST", true);
states = new Vector<State>();
steps = new ArrayList<String>();
}
// more members...
}
And here's the problem. When initializing states
I am getting this error:
Type mismatch: cannot convert from Vector to Vector
And here's where this got me. State
is a subclass of GenericState
. Why wouldn't I be able to initialize the Vector
that way? Am I missing something obvious? What should I do?