@Priority
The @Priority
annotation lets you control the order of executor matching when multiple executors accept the same input.
For example
To prioritize an executor with int
over one with String
, use @Priority(PriorityValue.HIGH)
:
java
@Command(name = "hello")
public class HelloCommand {
@Execute
void execute(@Arg String text) {
print("Matches String executor!! " + text);
}
@Execute
@Priority(PriorityValue.HIGH)
void execute(@Arg int number) {
print("Matches int executor! " + number);
}
}
All values of the PriorityValue
Now there’s no risk that the input /hello 10
will trigger the executor with the String
argument.
/hello <text/number>
Input
/hello 10Output
Matches int executor! 10/hello <text/number>
Input
/hello hiOutput
Matches String executor! hiWARNING - The order in the file does not matter!
Java discards method order during compilation.