A function declaration.
Because some functions have type parameters, getting a model requires applying type arguments to the
function declaration with apply()
in order to be able to invoke that function. For example, here is how you would
obtain a function model that you can invoke from a toplevel function declaration:
String foo<T>(){ return "Hello, our T is: ``typeLiteral<T>()``"; } void test(){ // We need to apply the Integer closed type to the foo declaration in order to get the foo<Integer> function model Function<String,[]> functionModel = `function foo`.apply<String,[]>(`Integer`); // This will print: Hello, our T is: ceylon.language::Integer print(functionModel()); }
For methods it is a bit longer, because methods need to be applied not only their type arguments but also
the containing type, so you should use memberApply()
and start by giving the containing closed type:
class Outer(){ shared String hello() => "Hello"; } void test(){ // apply the containing closed type `Outer` to the method declaration `Outer.hello` Method<Outer,String,[]> methodModel = `function Outer.hello`.memberApply<Outer,String,[]>(`Outer`); // We now have a Method, which needs to be applied to a containing instance in order to become an // invokable function: Function<String,[]> boundMethodModel = methodModel(Outer()); // This will print: Hello print(boundMethodModel()); }
no type hierarchy
Attributes | |
annotation | Source Codeshared formal Boolean annotation True if the current declaration is an annotation class or function. |
parameterDeclarations | Source Codeshared formal FunctionOrValueDeclaration[] parameterDeclarations The list of parameter declarations for this functional declaration. |
Inherited Attributes |
Attributes inherited from: Object |
Attributes inherited from: GenericDeclaration |
Methods | |
apply | Source Codeshared formal FunctionModel<Return,Arguments>&Applicable<Return,Arguments> apply<Return = Anything, Arguments = Nothing>(Type<Anything>* typeArguments) Applies the given closed type arguments to this function declaration in order to obtain a function model. See this code sample for an example on how to use this. Throws
Since 1.2.0 |
getParameterDeclaration | Source Codeshared formal FunctionOrValueDeclaration? getParameterDeclaration(String name) Gets a parameter declaration by name. Returns |
invoke | Source Codeshared default Anything invoke(Type<Anything>[] typeArguments = [], Anything* arguments) Invokes the underlying toplevel function, by applying the specified type arguments and value arguments. Parameters:
Throws
Since 1.2.0 |
memberApply | Source Codeshared formal FunctionModel<Return,Arguments>&Qualified<FunctionModel<Return,Arguments>,Container> memberApply<Container = Nothing, Return = Anything, Arguments = Nothing>(Type<Object> containerType, Type<Anything>* typeArguments) Applies the given closed container type and type arguments to this method declaration in order to obtain a method model. See this code sample for an example on how to use this. Throws
Since 1.2.0 |
memberInvoke | Source Codeshared formal Anything memberInvoke(Object container, Type<Anything>[] typeArguments = [], Anything* arguments) Invokes the underlying method, by applying the specified type arguments and value arguments. Parameters:
Throws
Since 1.2.0 |
staticApply | Source Codeshared formal FunctionModel<Return,Arguments>&Applicable<Return,Arguments> staticApply<Return = Anything, Arguments = Nothing>(Type<Object> containerType, Type<Anything>* typeArguments) Applies the given closed container type and type arguments to this
Since 1.3.1 |
staticInvoke | Source Codeshared default Anything staticInvoke(Type<Object> containerType, Type<Anything>[] typeArguments = [], Anything* arguments) Invokes the Parameters:
Since 1.3.1 |
Inherited Methods |
Methods inherited from: Object |
Methods inherited from: GenericDeclaration |