Prompts
Any number of parameters can be passed to an entrypoint. The user is then asked to enter these parameters when the program is started.
Use the @Prompt
annotation to change the prompt.
@Entrypoint
public void run(@Prompt("Enter your name") final String name) {
System.out.printf("Hello %s!%n", name);
}
Natively Supported Types
- boolean / Boolean
- char / Character
- double / Double
- int / Integer
- short / Short
- String
Special Wrappers:
- Arrays of the above types
- Scanner
Default Values
Default values can be set for parameters using the @Default
-annotation:
@Entrypoint
public void run(@Prompt("Name") @Default("Simon") final String name) {
System.out.printf("Hello %s!%n", name);
}
If no value is entered, the default value is used.
Note
Only inputs as string are possible. Enter as default value exactly what you expect from the user.
Arrays
(see ArrayPromptExample.java)
As announced above, it is possible to pass arrays. An array is then filled with values entered by the user with a separator (comma by default):
@Entrypoint
public void run(@Prompt("Enter Numbers") @Split(" ") final int[] numbers) {
System.out.println(Arrays.toString(numbers));
}
Note
Validators do not work for values inside the array.
For example, @Range
only limits the array size, not the individual values.
Last update:
2022-03-15