↑ Table of Contents ↑ | §2.4.2 Role creation via a regular constructor >> |
§2.4.1 Role creation via a lifting constructor
Lifting uses the default constructor for roles (see §2.3.1). This constructor can be invoked from client code, if the following rules are respected.
(a) Team context
The lifting constructor can be used only within the enclosing team of
the role to be instantiated. Thus, qualified allocation expressions
(someTeam.new SomeRole(..)
) may never use the lifting constructor.
(b) Fresh base object
If the argument to a lifting constructor invocation is a new
expression, creating a fresh base object, the use of the lifting constructor
is safe. Otherwise the rules of (c) below apply.
(c) Duplicate role runtime check
If it cannot be syntactically derived, that the argument to a lifting
constructor is a freshly created base object (b), a compile time warning will
signal that an additional runtime check is needed: It must be prevented that
a new role is created for a base object, which already has a role of the
required type in the given team. It is not possible to replace an existing
role by use of the lifting constructor. At runtime, any attempt to do so
will cause a org.objectteams.DuplicateRoleException
to be thrown.
This exception can only occur in situations where the mentioned compile
time warning had been issued.
§6.1 will introduce reflective functions
which can be used to manually prevent errors like a duplicate role.
↑ Table of Contents ↑ | §2.4.2 Role creation via a regular constructor >> |