Getter method for Generic type in BinarySearchTree
Hi, I had to write an implementation of a BinarySearchTree for an assignment.
I have the two classes, one 'BinarySearchTree' which basicly just points to the root, and the node that does most of the work:
publicclass BinaryNode<Kextends Comparable><K>,V>
{
public K _key;
public V _val;
private BinaryNode _left;
private BinaryNode _right;
....
public V getVal()//getter
{
return _val;
}
}
In my BinarySearchTree class I use this getter method like so:
V nodeValue;
nodeValue = (V) oldNode.getVal();
The thing I don't understand is why I have to cast the value returned? If I don't it won't compile!
It is working fine as is, but my lecturer is always saying to avoid casts.
Thanks,
Austin.

