§4.10.(e) Propagating type parameters
If a callin binding binds to a generic base method,
any type parameter(s) of the base method must be propagated into the role method
by declaring the callin binding with type parameters, too.
By matching a type parameter of a base method with a type variable
of the callin binding, this genericity is propagated through the callin binding.
1 |
class MyBase { |
2 |
<T> T getIt(T it) { return it; } |
3 |
} |
4 |
team class MyTeam { |
5 |
protected class MyRole playedBy MyBase { |
6 |
callin <U> U rm(U a) { return base.rm(a); } |
7 |
<U> U rm(U a) <- replace U getIt(U it); |
8 |
} |
9 |
} |
Explanation:
The callin binding declares a type parameter<U>
which is used to match all occurrences ofT
in the signature ofgetIt
. Thus the implementation ofrm
uses the typeU
in exactly the same generic way asgetIt
usesT
.