I would like to understand the following type of syntax.
Example:
public interface A < T extends A < T> > {
}
What is the logic of this interface ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This would be used as follows:
In other words, you are forced to make the parameter of
Athe classXitself, and something likeclass X implements A<Unrelated>is forbidden.This construction gives the interface access to
Xthrough the generic parameter, and the type restriction makes sure that it doesn’t get abused. For instance,Tcan now be assumed to expose all methods thatAdoes.Note that this construction is formally somewhat similar to the curiously recurring template pattern in C++ (although it is technically quite different). In both languages it allows the “base class” to reason about its ultimate derived usage.