Is your feature request related to a problem?
Currently, if one would want to add optional arguments, they would need to create multiple methods with the same semantics, which call each other:
@Executes
void run(ItemType type) {
run(type, 1, player);
}
@Executes
void run(ItemType type, int count) {
run(type, count, "Default name");
}
@Executes
void run(ItemType type, int count, String name) {
// ...
}
It is not far fetched to say that this is repetitive and annoying.
Describe the solution you'd like.
Instead, parameters wrapped in Optional<T> (or one of the similar types, like OptionalInt) can be provided at the end of the parameter list for values that do not have to be present:
@Executes
void run(ItemType type, OptionalInt count, Optional<String> name) {
int actualCount = count.orElse(1);
String actualName = name.orElse("Default name");
// ...
}
Describe alternatives you've considered.
No response
Other
For the primitive types and String, annotations for the default value could also be provided (@DefaultInt(1) or @DefaultString("Default name")), which would circumvent the usage of Optional for these, however the Optional<T> way would be very convenient for complex types, like World objects.
Is your feature request related to a problem?
Currently, if one would want to add optional arguments, they would need to create multiple methods with the same semantics, which call each other:
It is not far fetched to say that this is repetitive and annoying.
Describe the solution you'd like.
Instead, parameters wrapped in
Optional<T>(or one of the similar types, likeOptionalInt) can be provided at the end of the parameter list for values that do not have to be present:Describe alternatives you've considered.
No response
Other
For the primitive types and
String, annotations for the default value could also be provided (@DefaultInt(1)or@DefaultString("Default name")), which would circumvent the usage ofOptionalfor these, however theOptional<T>way would be very convenient for complex types, likeWorldobjects.