Inflearn Community Q&A
생성자 주입관련 질문 드립니다
Written on
·
266
0
생성자 주입 시, 딱 1번만 호출되는 것이 보장된다는 의미가
해당 클래스가 호출될 때 한번 호출된다는 의미인가요?
아니면 스프링은 싱글톤을 보장하기 때문에 1번만 호출 되는 것이 보장된다는 의미인건가요?
springoop
Quiz
66% of people got it wrong. Give it a try!
What are the main reasons why Field Injection is generally not recommended?
Because it is difficult to guarantee immutability
Because changing dependencies is easy
Because it's difficult to test with pure Java code
Because writing configuration code is complex
Answer 1
1
안녕하세요, youn 님. 공식 서포터즈 codesweaver 입니다.
.
생성자는 클래스를 생성할 때 단 한번만 호출되는 특수한 메서드 입니다.
클래스가 이미 인스턴스화 된 이후에는 이 생성자를 다시 호출할 방법이 없습니다.
그래서 '어떤 객체 A'를 생성자에서 주입한 뒤 별도의 getter/setter를 제공하지 않으면 외부에서 A를 명시적으로 다시 할당/호출할 방법이 없습니다.
.
감사합니다.





