3

If I have the following

val A = List(1,2,3)
val B = List(1,2,3)

will these two variables have the same memory address or not?

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • If a `List` is mutable, you can prove this for yourself. Put a different value into A() and then see if B() has changed. – lit May 20 '19 at 00:25

1 Answers1

7

They will not have the same memory address which can be confirmed using eq method which compares memory references like so

A eq B // returns false
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • Thanks Mario, I was asked this question in an interview ... but the question was if I have List a (1,2,3) and List b (1,2,3) ... what will happen in memory – Muhammad Magdi Youssif May 21 '19 at 10:39