Andre Roque
Andre Roque

Reputation: 543

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.

Upvotes: 3

Views: 2159

Answers (1)

&#211;scar L&#243;pez
&#211;scar L&#243;pez

Reputation: 235984

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;
    }

}

Upvotes: 2

Related Questions