First, since the SimpleGenericClass class is abstract, it must be a subclass.
Secondly, this is a general class, which means that somewhere inside the class you will almost certainly use the general parameter T as the type of the field.
public abstract class SimpleGenericClass<T...> { T x; }
Now the interesting thing first is that T bounded. Since it is declared as T extends SimpleGenericClass<?> , It can only be SimpleGenericClass<?> Or some subclass of SimpleGenericClass<?> . You also asked about thr ? . This is called a wildcard, and there is a pretty good explanation for this in the Java Wildcards Tutorial . In your case, we would say that it is "SimpleGenericClass of unknown". This is necessary in Java because SimpleGenericClass<Object> NOT a superclass of SimpleGenericClass<String> , for example.
An interesting second thing is that since T is a SimpleGenericClass some type, your class more than likely defines recursive structures. It seems to me that trees (think about expression trees), where SimpleGenericClass is a (abstract) node type, designed to subclass with all kinds of specialized node types.
UPDATE This SO question for self-limited generics may be helpful to you.
UPDATE 2
I went ahead and put together a code that illustrates how this can be used. An application does nothing but compile, and it shows you how general restrictions can provide some possibly significant restrictions.
public abstract class Node<T extends Node<?>> { public abstract T[] getChildren(); } class NumberNode extends Node { int data; public Node[] getChildren() {return new Node[]{};} } class IdentifierNode extends Node { int data; public Node[] getChildren() {return new Node[]{};} } class PlusNode extends Node { NumberNode left; NumberNode right; public NumberNode[] getChildren() {return new NumberNode[]{};} }
It's nice that NumberNode[] is a valid return type for PlusNode.getChildren ! Does it matter in practice? I don’t know, but it's pretty cool. :)
This is not a good example, but the question was quite open ("what can it be used for?"). Of course, there are other ways to define trees.
Ray toal
source share