Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic types in static method

I'm having a problem with Generic Types in static method. I have this code:

public class BST<E extends Comparable<E>> {

    public static class Node<T> {
        private T value;
        private Node<E> left, right, parent;

        private Node(T v) {
            value = v;
        }

        public String toString() {
            return value.toString();
        }
    }
....
}

then i wanna use Node in this static method:

public static <E> boolean equalTrees(Node<E> r1, Node<E> r2)

but at Node is giving me this error:

The member type BST.Node must be qualified with a parameterized type, since it is not static

I've searched and can't find the answer to that.

like image 704
Andre Roque Avatar asked Sep 11 '26 06:09

Andre Roque


1 Answers

Try this:

public class BST<E extends Comparable<E>> {

    public static <E> boolean equalTrees(Node<E> r1, Node<E> r2) {
        return false;
    }

    public static class Node<E> {
        private E value;
        private Node<E> left, right, parent;
    }

}
like image 116
Óscar López Avatar answered Sep 13 '26 19:09

Óscar López