Note: information on this page refers to Ceylon 1.0, not to the current release.
Callable references
A callable reference is an expression that references something (a function, method, or class) that can be invoked by specifying an argument list.
Usage
value classReference = String;
value methodReference = 1.plus;
value functionReference = sum<Integer>;
Description
Callable references introduce a level of indirection between the definition of a function, method, or class, and the invocation of the function, method, or class, allowing the definition of generic functions, called higher order functions, that operate upon callable references.
Type
The type of a callable reference is the callable type of the thing being referenced, so referring to the example above,
- the type of
classReferenceisString({Character*}), - the type of
methodReferenceisInteger(Integer). - the type of
functionReferenceisInteger({Integer+}),
Unreferenceable things
It's not possible to obtain a callable reference to an abstract
class, because calling it would be the same as instantiating the
abstract class. So, for example, the following code is illegal:
value objectReference = Object;
A callable reference to a generic declaration must specify type
arguments, as shown by functionReference in the example above.
This code is illegal:
value functionReference = sum;
Invocation
A callable reference may be invoked, for example:
classReference({'h', 'e', 'l', 'l', 'o'})
The interface Callable doesn't encode information about parameter
names. So a callable reference may only be invoked with a positional
argument list, not a named argument list.
See also
- Callable references in the Ceylon language specification