Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created June 9, 2023 22:55
Show Gist options
  • Select an option

  • Save monkey-codes/ccd5bf747e8e0b0b8e9c68bb1f299985 to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/ccd5bf747e8e0b0b8e9c68bb1f299985 to your computer and use it in GitHub Desktop.
val x = StringBuilder("hello")
val y = x.append(" world")
val r1 = y.toString() //hello world
val r2 = y.toString() //hello world
//Now if we substitute 'y' with the expression that created it 'x.append(" world")':
val r1 = x.append(" world").toString() //hello world
val r2 = x.append(" world").toString() //hello world world
r1 != r2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment