Don't people use @NonNull everywhere now? It's been a few years since I've programmed in Java but even then I feel like that was common practice.
Defaulting to not-nullable is a great idea. Much less boilerplate.
Personally I use notNull(..) over @NonNull since it actually fires when you expect it to (as opposed to whether your framework dispatcher interceptor trigger decided to invoke it)
@Test
public void foo() {
bar(null);
}
void bar(@NonNull String param) {
System.out.println(param);
}
All versions of that annotation let the null right through. I tried with: import lombok.NonNull;
import javax.validation.constraints.NotNull;
import io.micronaut.core.annotation.NonNull;
import org.springframework.lang.NonNull;
import reactor.util.annotation.NonNull; @Test
public void foo() {
final Map<String, Integer> map = new HashMap<>();
map.put("present", 1);
bar(map.get("missing"));
}
void bar(@NotNull Integer param) {
System.out.println(param);
}
"No problems found"