메소드 인자에서 @NotNull 과 @NonNull
@Nullable 그리고 @NotNull
@NotNull을 변수에 붙여서 검증에 사용할 수 있다. 하지만 메소드 인자에서 이 둘은 아무런 역할도 하지 않는다. 메소드 인자에서 이 둘은 단순한 문서 작성 도구로 작용한다.
유효성 검사시 메서드 인자에는 @NotNull이 아닌 @Valid 를 사용해야한다.
@Valid 세팅 및 사용법
간단소개 API를 만들다 보면 유효성체크를 꼭하기 마련이다. 매번 유효성체크를 로직을 작성하는 것도 매우 반복되는 일이다. Javax에서 @Valid 어노테이션을 제공해주고 있는대 Bean Validation을 아
cchoimin.tistory.com
메소드 인자에서 유효성 검사하기 : lombok @NonNull
롬복에서 제공하는 @NonNull은 메서드의 인자에 사용하면 null이 들어올 시 NullPointerException을 발생시킨다.
참조
Using NotNull Annotation in method argument
I just started using the @NotNull annotation with Java 8 and getting some unexpected results. I have a method like this: public List<Found> findStuff(@NotNull List<Searching> searchin...
stackoverflow.com
Javax @NotNull annotation usage
I have a simple method to get a list of documents for a given companyId. Here is the method: @Override public List<Documents> getDocumentList(@NotNull Integer companyId) { Company compan...
stackoverflow.com