[Kotlin][deep copy] 리스트의 마지막 원소가 사라져 버렸다.

Kotlin 코드에서 deep copy 를 하지 않은 채 원본을 clear 하니까 리스트의 마지막 원소가 사라지는 문제가 발생했다. 리스트의 마지막 원소만 사라진다. val testList: MutableList<Int> val listOfTestList: MutableList<List<Int>> .forEach 블록 내에서 testList 를 몇 개 생성하면서 listOfTestList 에 추가하였다: listOfTestList.add(testList) 나중에 listOfTestList 를 출력해 보니 감쪽같이 마지막 원소만 사라졌다. 마지막 element 가 [] 이렇게 빈 채로 … 더 읽기

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny