Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Generic Types


Tags:

Hi there, hope you guys can help :)

I have a generic class:

public class Tree<T> {
        ...
private Node<T> root;

public Tree(T data) {
root = new Node<T>(data);
}
...
}

and a class which extends this class:

public class TicTacToeTree extends Tree<Board> {

        public static void main(String[] args) {

                // This does not work
TicTacToeTree tree = new TicTacToeTree(new Board());

                // This does work
Tree<Board> btree = new Tree<Board>(new Board());

}

}

I get the following error message "The constructor TicTacToeTree(Board) is undefined". I can't see why it doesn't work with the TicTacToeTree but does if you create the tree with type Board.

Any help would be appreciated.

Thanks