I am learning generics in my Data Structures class and during the reading I fully understand it but when it comes for me to write my own code and imlement it via a project or assignment, it takes me forever because I have to go back through the book and find spots where it applies to what I'm doing.
Anyways, I have a code piece:
public class TelephoneBinaryTree<T extends Integer> implements BinaryTreeADT<T> { TelephoneTreeNode<T> root; int size; public TelephoneBinaryTree() { size = 0; } public TelephoneBinaryTree(int a, int b, int c) { root = new TelephoneTreeNode<>(a, b, c); size = 1; } public T getRoot() { return root; //Type mismatch: cannot convert from TelephoneTreeNode<T> to T }
Why does it give me a mismatch? I cannot find anywhere that explains this.