Skip to content

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
callable
templates
template
params
type
type

resultTypeLang\Type\Callable\CallableTypeNode

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
callable
templates
template
of
type
params
type
type

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
callable
templates
template
of
type
template
super
type
template
type
params
type
type
type

resultTypeLang\Type\Callable\CallableTypeNode

A variance.

callable<covariant T>(T): void
callable
templates
template · covariant
params
type
type

resultTypeLang\Type\Callable\CallableTypeNode

Every limit on one parameter.

callable<T of Some super Any = int>(T): void
callable
templates
template
of
type
super
type
type
params
type
type

resultTypeLang\Type\Callable\CallableTypeNode