Like A Flowing Cloud

기본 본문

Salesforce

기본

Like A Flowing Cloud 2022. 12. 26. 16:42

#1.
String s1 = '이름';
String s2 = s1;
s2 = '이름2';
system.debug(s1); 
// 답: 이름

#2.
Account a1 = new Account();
a1.name = '이름';
Account a2 = a1;
a2.name = '이름2';
system.debug(a1.name);
// 답: 이름2

>> 왜냐하면 위에 #1은 String 을 바꾸는 것이지만 #2는 a1에 주소를 할당하는 것이기 때문에 a2 = a1 일 경우 a1 과 같은 주소가 할당되는 것이기 때문에