Say I have a interface
interface Rankable {}
and two classes implement this interface
class Worker implements Rankable {}
class Student implements Rankable {}
Now I define a generic class
class Node<T extends Rankable> {
T data;
Node left;
Node right;
Node parent;
};
Actually I don't know why use extend here.
Then I define a class BST
class BST<T extends Rankable> {
//field
Node root;
//method
void insert(Node node){};
};
So, I convert Student and Worker to Node, Can I have two different Node types (Node<Student> Node<Worker>). in the same BST<T>.
If answer yes, why? How that extends a interface work?
List list = new ArrayList();
list.add(1);
list.add("hello");
//Why this code cannot work, I think it's same with code above
I'm new to Java, Please be patient.