Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Side-effects are bad, right?
// What output does this yield? What should it? (try with either 2.12.x or 2.13.x)
// (spoiler: https://github.com/scala/bug/issues/10788)
object Test {
class Box[T](t: T) {
def foo: T = {
println("effect")
t
}
}
object Box {
def apply(x: String): Box[x.type] = new Box[x.type](x)
}
def main(args: Array[String]): Unit = {
val bar = Box("foo").foo
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.