<< §4.6 Overriding access restrictions | ↑ Table of Contents ↑ | §4.8 Callin precedence >> |
§4.7 Callin binding with static methods
The normal case of callin bindings refers to non-static methods on both sides (base and role). Furthermore, in Java inner classes can not define static methods. Both restrictions are relaxed by the following rules:
(a) Static role methods
A role class may define static methods (see also §1.2.1.(f)).
(b) Binding static to static
A callin binding may bind a static role method to one or more static base methods. It is, however, an error to bind a static base method to a non-static role method, because such binding would require to lift a base object that is not provided.
(c) before/after
In addition to the above, before
and after
callin bindings may also bind a static role method to non-static base methods.
(d) replace
In contrast to §4.7.(c) above, a replace
callin binding
cannot bind a static role method to a non-static base method.
The following table summarizes the combinations defined above:
<- | base method | ||
static | non-static | ||
role method |
static | OK | before/after : OKreplace : illegal |
non-static | illegal | OK |
(e) No overriding
Since static methods are not dynamically bound, overriding does not
apply in the normal semantics. Regarding callin bindings this has the
following consequences (assuming a role RMid
played by
BMid
plus its super-class BSuper
and its sub-class
BSub
.
- If a static base method
BMid.m
is bound by a callin binding this has no effect on any methodm
inBSub
. - If a callin binding mentions a method
m
which is not present inBMid
but resolves to a static method inBSuper
the binding only affects invocations asBMid.m()
but notBSuper.m()
. If the latter call should be affected, too, the callin binding must appear in a role class bound toBSuper
, notBMid
. - In order to bind two static base methods with equal signatures, one being
defined in a sub-class of the other one, two roles have to be defined
where one role refines the
playedBy
clause of the other role (say:public class RSub extends RMid playedBy BSub
). Now each role may bind to the static base method accessible in its direct base-class.
<< §4.6 Overriding access restrictions | ↑ Table of Contents ↑ | §4.8 Callin precedence >> |