I have below class hierarchy.
First class
class First<T> {
}
Second class
class Second<T> extends First<T> {
}
Third Class
class Third<T extends First<T>> {
}
Error line:
Third<Second<String>> name = new Third<Second<String>>();//Compilation error
Bound mismatch: The type Second<String> is not a valid substitute for the
bounded parameter <T extends First<T>> of the type Third<T>
I am really confused with above error. Can you please explain Why this compilation error occurs?
T extends First<T>is not the same asSecond<String>, because T is bound both toStringand something that extendsFirst<T>.I have the feeling that you want to use different parameters in Third, doing something like