↑ Table of Contents ↑ |
§9.2.1.(a) Instance constrained type parameters
In addition to normal usage, a value parameter can be applied nested to a regular type parameter:
class MyClass<YourType aName, DependentParam<@aName>> { ...
Here the type parameter DependentParam
is constrained to be anchored to aName
.
If a value parameter is used as a constraint for a regular type parameter any substitution for the type parameter must also supply a value matching the value parameter. The class from above could be applied like this:
final YourType anchor = new YourType(); MyClass <@anchor, YourDependent<@anchor>>
Within the declaring element (class or method) applications of the type variable representing the instance constrained type parameter must repeat the anchor verbatim, i.e., no substitutions are performed here.
↑ Table of Contents ↑ |