LogHouse

@AllArgsConstructor와 @RequiredArgsConstructor 차이

에 쓴 글, 2분이면 읽어요.

ddaakk의 프로필 사진

직접 부딪히며 배운 개발 경험과 기술 이야기를 기록합니다.

@RequiredArgsConstructor 초기화 되지 않은 final 필드와 @NonNull 어노테이션이 붙은 필드에 대한 생성자를 생성합니다.

@AllArgsConstructor 모든 필드에 대한 생성자를 생성합니다.

@RequiredArgsConstructor


@RequiredArgsConstructor generates a constructor with 1 parameter for each field that requires special handling. All non-initialized final fields get a parameter, as well as any fields that are marked as @NonNull that aren't initialized where they are declared. For those fields marked with @NonNull, an explicit null check is also generated. The constructor will throw a NullPointerException if any of the parameters intended for the fields marked with @NonNull contain null. The order of the parameters match the order in which the fields appear in your class.

@AllArgsConstructor


@AllArgsConstructor generates a constructor with 1 parameter for each field in your class. Fields marked with @NonNull result in null checks on those parameters.

반응과 댓글

첫 반응을 남겨 주세요

0개의 댓글