How to instantiate a generic recursive class in Java

ycesar :

My problem is that I am using a class not developed by me (I took it from Microsoft Azure SDK for Java). The class is called Node and you can see it here.

As you can see the class is a generic class declared recursively like this:

public class Node<DataT, NodeT extends Node<DataT, NodeT>> {
      ...
}

When I try to instantiate it I don't know how to do it. I am doing this but I know IT IS NOT the way because it has no end:

Node<String, Node<String, Node<String, Node<...>>>> myNode = new Node<String, Node<String, Node<String, Node<...>>>>;

I hope you understand my question. Thanks.

Radiodef :

You have to declare a class which extends Node so you can use the name of the class:

class StringNode extends Node<String, StringNode> {
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=444272&siteId=1