Feature Overview
This feature sets the default value for method parameters.
This feature sets the default value for method parameters.
None
public class DefaultValueDemo {
public static Integer init() {
return 0;
}
public static Integer add(
@defaultValue(init()) Integer a,
Integer b = init()
) {
return a + b;
}
}
public class DefaultValueDemo {
public static Integer init() {
return 0;
}
public static Integer add(Integer a, Integer b) {
a = (a == null) ? init() : a;
b = (b == null) ? init() : b;
return a + b;
}
}
@defaultValue
can only be applied to method parameters.
Or you can append = ...
expressions to the parameter name.
Contribute on Github! Edit this section.