Using Type Parameters Created in One Class in a Different Class

Viewed 44

I defined two type parameters, T and G, in one of my classes (Table). This Table class is using a LinkedList. I have made another class (Node) for the nodes of the LinkedList with a few setters and getters. I would like to use the same T and G in my Table class; which is making the LinkedList nodes. However, I am running into issues.

How do I use the same type parameters in a different class?

public class Table<T, G> {
        ...
}

public class Node {
   public T get(G g) {
       ...
   }
}
1 Answers

Node needs to declare the types too...

public class Table<T, G> {

    private List<Node<T, G>> list = new ArrayList<>();
    
}

public class Node<T, G> {

    public T get(G g) { ... } 
}
Related