What is a deep copy? - Cracking the Java Coding Interview

preview_player
Показать описание
Cracking the #Java #Coding #Interview - Question 142: What is a deep copy?
Рекомендации по теме
Комментарии
Автор

While implementing a Conway's game of Life in Java I had the darndest time trying to figure out why me making a copy of an array was giving me such a hard time.

It was because I was only making copies of the array itself and not deep copying the nested arrays. State[][]

Lesson learned! Haha.

Gennys
Автор

The way he explains is a dream.. never found anyone who explained with such smile and calmness.

AkhileshKumar-xqul
Автор

I'm addicted to your channel. Can't wait for the next upload!

MyCodingDiary
Автор

Awesome, ex deep copy through constructure and shadow cope through setter based

BSReddy
Автор

Nit: List.copyOf() doesn't check if a list is non-modifiable, it checks if the list is immutable.

"Non-modifiable" can have a different connotation in Java, since the Collections.unmodifiableX() factory methods return unmodifiable **views**. The state of an unmodifiable view **can change**. It's just that changes cannot be made via the unmodifiable view, but code that holds a reference to the backing collection can indeed make changes to it.

This is why immutable collections are different. List.of() and List.copyOf() return immutable collections. returns unmodifiable views.

roge
Автор

Simply deep copy creates an object inheritance

whiz-code
Автор

Next question that arises in my mind is, how deep the deep copy should go?

JavierFausLlopis