Syntax
Generic callables
A callable may declare the template parameters
it introduces: a <...> list between the name and the parameters.
A callable returning the type of its argument.
callable<T>(T): T
resultTypeLang\Type\Callable\CallableTypeNode
Template parameters
Section titled “Template parameters”A template parameter is a name, optionally prefixed with a variance
(covariant, contravariant or invariant) and followed by up to three
limits. Each limit is written at most once, in this order:
| Limit | Meaning |
|---|---|
of T, as T |
upper bound: the argument is a subtype of T |
super T |
lower bound: the argument is a supertype of T |
= T |
default: the type taken when no argument is passed |
of and as mean the same and are kept as written. The words are
case-sensitive: OF is an ordinary name.
An upper bound.
callable<T of Some>(T): T
resultTypeLang\Type\Callable\CallableTypeNode
Several parameters, each with a limit of its own.
Closure<T of Some, U super Any, V = int>(T, U): V
resultTypeLang\Type\Callable\CallableTypeNode
A variance.
callable<covariant T>(T): void
resultTypeLang\Type\Callable\CallableTypeNode
Every limit on one parameter.
callable<T of Some super Any = int>(T): void
resultTypeLang\Type\Callable\CallableTypeNode
Limits belong to a callable: a type with template arguments has none.
Collection<T of Some>
errorMalformedSyntaxException Invalid template arguments, "," or ">" is expected
Only of, as and super bound a parameter.
callable<T whatever Some>(): void
errorMalformedSyntaxException Invalid template arguments, "," or ">" is expected
Each kind of limit is written at most once.
callable<T of Some as Any>(): void
errorMalformedSyntaxException Invalid template arguments, "," or ">" is expected
The lower bound cannot stand before the upper one.
callable<T super Any of Some>(): void
errorMalformedSyntaxException Invalid template arguments, "," or ">" is expected
A limit behind the default would bound the default itself: here of Some
would bound int, not T.
callable<T = int of Some>(): void
errorMalformedSyntaxException Invalid template arguments, "," or ">" is expected