woowacourse / tecoble-comments

0 stars 0 forks source link

tecoble/post/2020-06-11-value-object/ #10

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

VO(Value Ojbect)란 무엇일까? | javable

프로그래밍을 하다 보면 VO라는 이야기를 종종 듣게 된다.

https://woowacourse.github.io/tecoble/post/2020-06-11-value-object/

cs09g commented 3 years ago

타이틀에 오타가 있습니다.

aliwo commented 3 years ago

잘 봤습니당! 그런데 의문이 있습니다! int[] a = {1,2,3}; int[] b = a; System.out.println(a == b); 하면 항상 true 가 나오는데요... 이 경우엔 얕은 복사가 아니라 "할당" 이 아닐까요?

bearjun05 commented 1 year ago

잘 봤습니다 감사합니다.

xonic789 commented 8 months ago

@aliwo 당연히 true가 나옵니다. 메모리 관점에서 보면 배열 -> 힙 메모리 변수 (a, b) -> 스택 메모리

int[] a = {1,2,3}; -> 힙 메모리에 할당된 메모리 주소 a 변수에 할당 int[] b = a; -> 스택 메모리에 할당된 a 메모리 주소, 즉 b 가 저장된 힙 메모리 주소

자바에서는 == 동등 논리 연산자는 기본적으로 참조 변수면 메모리 주소를 비교하기 때문에 true입니다.