@Retention(value=RUNTIME) @Target(value=PARAMETER) public @interface Parameter
A typical use is to derive names for the parameters of user-defined functions.
Here is an example:
public static class MyLeftFunction {
public String eval(
@Parameter(name = "s") String s,
@Parameter(name = "n", optional = true) Integer n) {
return s.substring(0, n == null ? 1 : n);
}
}
The first parameter is named "s" and is mandatory, and the second parameter is named "n" and is optional.
If this annotation is present, it supersedes information that might be
available via
Executable.getParameters() (JDK 1.8 and above).
If the annotation is not specified, parameters will be named "arg0", "arg1" et cetera, and will be mandatory.
public abstract String name
The name is used when the function is called
with parameter assignment, for example foo(x => 1, y => 'a').
public abstract boolean optional
An optional parameter does not need to be specified when you call the function.
If you call a function using positional parameter syntax, you can omit
optional parameters on the trailing edge. For example, if you have a
function
baz(int a, int b optional, int c, int d optional, int e optional)
then you can call baz(a, b, c, d, e)
or baz(a, b, c, d)
or baz(a, b, c)
but not baz(a, b) because c is not optional.
If you call a function using parameter name assignment syntax, you can
omit any parameter that has a default value. For example, you can call
baz(a => 1, e => 5, c => 3), omitting optional parameters b
and d.
Currently, the default value used when a parameter is not specified is NULL, and therefore optional parameters must be nullable.
Copyright © 2012–2023 The Apache Software Foundation. All rights reserved.