Answer the question
In order to leave comments, you need to log in
What is the essence of self-bounded types?
Hello! I read this article, a couple of answers on StackOverFlow, but there are still a lot of questions about self-bounded types.
As I understand correctly, this is a class whose type argument is its derived class, and this form of notation is used so that the methods of the base class can directly use instances of the derived class.
However, the question arises - why is it not possible to simply specify a reference to the base class in the arguments of the methods instead of using parameterization? Polymorphism will just provide what you need. If you need, for example, only an instance of a derived class to compare with something, then this is fine. And if you want to use derived class methods, you can use RTTI. class Enum<E extends Enum<E>>
Answer the question
In order to leave comments, you need to log in
Not in this case. Here the task is to say already during compilation that the program is incorrect and cannot be compared, for example, enum TrLight { RED, YELLOW, GREEN }
and enum Pet { CAT, DOG, HEN }
.
For a Java machine, TrLight and Pet are the same class, template classes are checked during compilation!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question