| << §8 Join Point Queries | ↑ Table of Contents ↑ | §A ObjectTeams/Java Syntax >> |
Within the angle brackets that mark the parameters of a generic class also value parameters can be declared. In contrast to a type parameter, a value parameter is denoted as a pair of two identifiers: a type and a free name, e.g.,
class MyClass<YourType aName> { ...Note that value parameters are valid for classes only, not for interfaces.
Within the given class (MyClass) the parameter name (aName) can be used
like a final field of the given type (YourType). In contrast to regular final fields
the assignment to this name occurs even before the constructor is executed.
Any role type can be interpreted as a value dependent type, however, in the declaration of a role type the value parameter remains implicit: it is identical to the enclosing team instance.
When using a class which declares one or more value parameters (type anchors) a corresponding anchor value has to be provided.
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.
Two value dependent types (anchored types) are considered conform only if the anchors of both types refer to the same object(s). The compiler must be able to statically analyze this anchor identity.
Only two substitutions are considered for determining anchor identity:
this as the anchor of any of its types,
type checking an application of this method performs the following substitutions:
this expression is substituted by the actual call target
of the method application.
Outer.this expression is substituted by the corresponding
enclosing instance of the call target.
final identifier to another final
identifier are transitively followed, i.e., if t1, t2 are final,
after an assignment t1=t2 the types C<@t1> and
C<@t2> are considered identical. Otherwise C<@t1>
and C<@t2> are incommensurable.
After anchors have been proven identical, the raw types are checked for compatibility using the standard Java rules.
Types with value parameters that are declared outside a team cannot be overridden, as roles can be. Therefor, implicit inheritance does not apply for these types.
Currently only the first parameter of a class may be a value parameter. This restriction may be removed in the future.
| << §8 Join Point Queries | ↑ Table of Contents ↑ | §A ObjectTeams/Java Syntax >> |