강의

멘토링

커뮤니티

Inflearn Community Q&A

nhs0912's profile image
nhs0912

asked

Yoon Jae-seong's introductory course through hands-on experience for Spring Framework developers

Lecture 11: Constructor Injection

생성자 파라미터 순서 getBean 문의

Written on

·

216

0

생성자 파라미터 순서에 대해서 강의를 들었는데요. 

xml에 index값을 하지 않고 

똑같은 생성자인데 파라미터 순서만 다른 생성자를 3개 부여 하면

어떤 우선순위로 getBean을 하나요? 

이런식으로 하면 "TestBean의 생성자" 가 print되는데요. 

만약 중간에 있는 생성자(2번째)를 주석처리하고 실행하면 

맨 마지막꺼가 getBean 되더라고요. 이게 어떤 우선순위인지 실행만으로 찾기 힘드네요 ㅠㅠ 

-----------------------------------------------------

public TestBean(int data1,double data2,String data3) {

System.out.println("TestBean의 생성자 : 변수 3개");

this.data1 = data1;

this.data2 = data2;

this.data3 = data3;

}

public TestBean(int data1,String data3,double data2) {

System.out.println("TestBean2의 생성자 : 변수 3개");

this.data1 = data1;

this.data2 = data2;

this.data3 = data3;

}

public TestBean(String data3,int data1,double data2) {

System.out.println("TestBean3 생성자 : 변수 3개");

this.data1 = data1;

this.data2 = data2;

this.data3 = data3;

}

-------------------------------------------------------------------------------------------

springjava

Answer 1

0

nhs0912님의 프로필 이미지
nhs0912
Questioner

보시기 힘드실거 같아 이미지로도 첨부합니다. 

nhs0912's profile image
nhs0912

asked

Ask a question