I'm encountering the error message "non-static type variable T cannot be referenced from a static context". It shows Required type: Node <T> Provided: Node<T>
I'm struggling to understand what I am doing wrong, but as I understand, there's an issue with using the generic type T in static context. I would appreciate any help, thanks.
class BinaryTree<T> {
private static Node<T> rootNode;
public static class Node<T> {
private final T value;
private Node<T> left;
private Node<T> right;
public Node(T value) {
this.value = value;
this.left = null;
this.right = null;
if (rootNode == null){
rootNode = this;
}
}
}
public BinaryTree() {
rootNode = null;
}
}
I am trying to implement a Binary Tree. I have a static inner class Node inside a BinaryTree class with a generic type. I want to set a static variable (rootNode) within the inner class based on a condition if it is null.