In the above video, when Mosh is refactoring the put method (@ 6:20) he states that if we initialize a new linkedlist using the local variable “bucket” instead of using “entries[index]” then it won’t initialize that cell in the array, only the local variable. Why is that?
Because we want to update what entries[index]
points to.
When we assign entries[index]
to a variable named bucket
, we are making that variable point at the same thing currently referenced by entries[index]
, but reassigning bucket
just updates what bucket
points to rather than updating what entries[index]
points to. This is just the fundamental way variables work (at least in Java).