§1.2.4 Type tests and casts

In accordance with §1.2.2.(e), in OT/J the instanceof operator and type casts have extended semantics for roles.

(a) instanceof

For role types the instanceof operator yields true only if both components of the type match: the dynamic role type must be compatible to the given static type, and also type anchors must be the same instance.

(b) Casting

Casts may also fail if the casted expression is anchored to a different team instance than the cast type. Such failure is signaled by a org.objectteams.RoleCastException.

(c) Class literal

A class literal of form R.class is dynamically bound to the class R visible in the current instance context. Using a class literal for a role outside its enclosing team instance (see §1.2.2) requires the following syntax:

RoleClass<@teamAnchor>.class