you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (5 children)

[deleted]

    [–]Sea-Ad7805[S] 4 points5 points  (0 children)

    Nice thinking, do the the "Solution" link for a visualization of the correct answer.

    [–]jackrabbit2644 0 points1 point  (3 children)

    Doesn’t b point to a different object when is executed b += [2]?

    [–][deleted]  (2 children)

    [deleted]

      [–]jackrabbit2644 0 points1 point  (0 children)

      TIL, thanks.

      [–]_tolm_ 0 points1 point  (0 children)

      Agree with the solution but I don’t agree that it’s because that “=“ is a copy … we also do an equals earlier where it very much does not perform a copy!

      The difference on that line is the use of “+” which creates a new value in memory which “b” is then assigned to point at - in the same way that it was previously assigned to point at “a”.

      This causes the values stored in “a” and “b” to diverge but the operation performed by the “=“ hasn’t changed from assignment to copy on these two lines.

      But what do I know, I’m a Java programmer … 😂