§6.1.(c) Class literals for roles
The Java syntax for so-called class literals, MyClass.class
(see JLS §15.8.2)
can be used for role types with slightly changed semantics: Role types are virtual types (§1.3.1)
that are bound dynamically (§1.3.1.(e)). This applies to role class literals, too.
From this follows the constraint that a role class literal can only be used within the non-static context of a team,
ie., for evaluating a role class literal an enclosing team instance must be in scope.
Unlike regular type checking for role types, the class literal itself does not have a dependent type.
Thus type checking of calls to methods like hasRole(Object, Class)
cannot detect, whether the Class
instance
has actually been obtained from the correct team instance. Any attempt to pass a class that is not known
as a bound role within the given team results in an IllegalArgumentException
at run-time.