Feature Overview
This feature generates a method with optional parameters.
This feature generates a method with optional parameters.
None
public class OptionalDemo {
public static Integer add(Integer a, @optional Integer b, Integer c?) {
b = b == null ? 0 : b;
c = c == null ? 0 : c;
return a + b + c;
}
}
public class OptionalDemo {
public static Integer add(Integer a, @optional Integer b, Integer c?) {
b = b == null ? 0 : b;
c = c == null ? 0 : c;
return a + b + c;
}
}
public class OptionalDemo {
public static Integer add(Integer a, Integer b, Integer c) {
b = b == null ? 0 : b;
c = c == null ? 0 : c;
return a + b + c;
}
public static Integer add(Integer a, Integer b) {
return add(a, b, null);
}
public static Integer add(Integer a) {
return add(a, null);
}
}
public class OptionalDemo {
public static Integer add(Integer a, Integer b, Integer c) {
b = b == null ? 0 : b;
c = c == null ? 0 : c;
return a + b + c;
}
public static Integer add(Integer a, Integer b) {
return add(a, b, null);
}
public static Integer add(Integer a) {
return add(a, null);
}
}
@optional
can only be used as the rear parameters in a method.
Or you can append ?
to the parameter name.
Contribute on Github! Edit this section.