↑ Table of Contents ↑ | §9.2.2 Type conformance >> |
§9.2.1 Parameter substitution
Substitution of a type anchor of a class MyClass<YourType p>
is denoted as
MyClass<@v>
.
In this term v
must be a value which is conform to the declaration of the value
parameter "YourType p
", ie., v
must have the static type YourType
.
The value passed for substituting a type anchor must be a path of variables declared as final
.
Obviously, only the first element in such a path can be a local variable or a method argument,
all other elements have to be fields. The reason for requiring final variables is
in type checking as discussed next.
Note:
Externalized roles as defined in §1.2.2.(b) are a special case of types with a value parameter, where the value is an instance of the enclosing team.(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 ↑ | §9.2.2 Type conformance >> |