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

July 2025

S M T W T F S
  12345
6789 1011 12
131415 16171819
20212223242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 17th, 2025 10:37 pm
Powered by Dreamwidth Studios