1

I am not able to create Class with Generics. I want generic type parameter for the class, which itself accept generics as shown. Is there any way to achieve this?

public class Node<D, C<D,C>> {
    D data;
    C<D,C> children;

    public D getData() {
        return data;
    }

    public void setData(D data) {
        this.data = data;
    }

    public C<D,C> getChildren() {
        return children;
    }

    public void setChildren(C<D,C> children) {
        this.children = children;
    }
}
4

1 回答 1

4

You can have Generics with two parameters like:

public class Node<T, X> 

Then you can declare objects like:

Node<String, Node<String, String>> node;
于 2013-05-05T18:36:26.403 回答