Quote (Cattotonic @ Nov 7 2012 11:56am)
I'm getting the error: Implicit super constructor Player() is undefined. Must explicitly invoke another constructor.
I'm trying to use the following constructors in the child classes:
Code
public Computer(TreeSet<String> t) {}
public Human(TreeSet<String> t) {}
While the parent (Player) class has the following constructor:
Code
public Player(Dictionary d) {}
adding the code "super(t)" as the fist line in the construct should fix your issue. This tells the jvm you want to pass the object through the constructor defined in the parent class.
Code
final abstract class Player {
protected final Dictionary dictionary;
Player(Dictionary<?> dictionary){
this.dictionary = dictionary;
}
/**getter*/
}
Code
class HumanPlayer extends Player {
HumanPlayer(TreeSet<?> dictionary) {
super(dictionary);
}
}
This is basically what you would do, but the most optimal way(depending on how you plan to use the code) would be to simply have something like the following:
Code
final abstract class Player {
public abstract Dictionary<?> getDictionary();
}
This way you can simple inherit the method in the child class and return the dictionary object of your choce.
all this was written in this chatbox so there is no formatting etc..
If you want to get even more advanced you can get into generics but it doesn't seem you're there yet.
This post was edited by Saxic on Nov 7 2012 09:37pm