after a lot of debate at my new posting we came with this conventionfor public methods:
- a primitive means not null (obvious)
- an Object Backed by a primitive means it's nullable
- even if it's not a Validated class annotate the params with @NotNull and @NotBlank when required.
- if a spring component use the @Validated annotation as well
- you are free to wrap the parameter with Optional<> inside the method call.
// response will never be null public @NotNull String methodCall( int startValue, // required Integer endValue, // not required BigDecimal minimum, //not required @NotNull BigDecimal maximum, //required @NotBlank String username, //required, not blank String comment //not required ){ return String.format("startValue:%d, endValue:%d, minimum:%s, maximum:%s, username:%s, comment:%s", startValue, endValue, minimum, maximum, username, comment); }