Annotation Type Parameter


@Retention(RUNTIME)
@Target(PARAMETER)
public @interface Parameter
Annotation that supplies metadata about a function 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.

  • Required Element Summary

    Required Elements 
    Modifier and Type Required Element Description
    String name
    The name of the parameter.
  • Optional Element Summary

    Optional Elements 
    Modifier and Type Optional Element Description
    boolean optional
    Returns whether the parameter is optional.
  • Element Details

    • name

      String name
      The name of the parameter.

      The name is used when the function is called with parameter assignment, for example foo(x => 1, y => 'a').

    • optional

      boolean optional
      Returns whether the parameter is 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.

      Default:
      false