juan_gandhi: (Default)
[personal profile] juan_gandhi
scala> def f(x: AnyRef) = System.identityHashCode(x)
f: (x: AnyRef)Int

scala> def s = Set("a", "bc", "def")
s: scala.collection.immutable.Set[String]

scala> val list = List(s, s)
list: List[scala.collection.immutable.Set[String]] = List(Set(a, bc, def), Set(a, bc, def))

scala> val s1 = list.map(f).toSet
s1: scala.collection.immutable.Set[Int] = Set(508760925, 1987354705)

scala> val s2 = list.toSet.map(f)
s2: scala.collection.immutable.Set[Int] = Set(508760925)

Date: 2018-12-20 09:46 am (UTC)
From: [personal profile] sassa_nf
:-)

You want
val s = Set("a", "bc", "def")
but that's a good puzzler!

Date: 2018-12-20 10:15 am (UTC)
From: [personal profile] sassa_nf
Other than that - sure, that's interaction with Java. There are other things that make identity of two equal immutable Sets observable. There is even one mutable aspect of every immutable object: the monitor used to synchronize, wait and notify. So when synchronizing, you do need to make sure the identity of the object visible to all threads is the same.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

June 2025

S M T W T F S
1 2345 6 7
8 9 10 11 121314
15161718 1920 21
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 28th, 2025 01:59 am
Powered by Dreamwidth Studios