A
A
Alexey24112020-08-11 17:50:38
Java
Alexey2411, 2020-08-11 17:50:38

What is the practical use of self-restriction in Java?

What is the meaning of this snippet? A class can only take an instance of itself as a type parameter, but what's the use of that?

public class MyGeneric<T extends MyGeneric<T>> {
    T element;
    public MyGeneric(T element) {
        this.element = element;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-08-12
@Aleksey2411

To answer something ...)))
It is very similar to Building a Tree, but there is only one parameter in the class - so let's call it a simple linked list. Simple because only the parent knows the child. More parameters and the tree is ready.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question