I came across with following:
I understand this :
In a class's type parameter section, a type variable T directly depends on a type variable S if S is the bound of T, while T depends on S if either T directly depends on S or T directly depends on a type variable U that depends on S (using this definition recursively).
But
It is a compile-time error if a type variable in a class's type parameter section depends on itself.
what does it mean ? Reference
What the statement means is that a type parameter variable cannot depend on itself. The following code is not allowed :
class Generic<T extends T> {
}
Here T
is a type-parameter variable and it cannot depend on itself (directly or inderictly). On the other hand, the following code is allowed :
public class GenericRecursive<T extends GenericRecursive<T>> {
}
It is a compile-time error if a type variable in a class's type parameter section depends on itself.
The parameter cannot derives from itself.
For example it is not legal :
class YourClass<S extends S> {
}
But you probably will not use this as it makes no really sense.
You could do that for example :
class YourClass<T extends S, S extends T> {
}
And it will not compile too because T
depends on S
that depends on itself (cycle)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With