Guest User

Untitled

a guest
Nov 22nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. var s: Int = 0
  2.  
  3. def function(s: Int): Boolean={
  4.  
  5. s += 1
  6.  
  7. return true
  8.  
  9. }
  10.  
  11. implicit class MutableInt(var value: Int) {
  12. def inc() = { value+=1 }
  13. }
  14.  
  15. def function(s: MutableInt): Boolean={
  16. s.inc() // parentheses here to denote that method has side effects
  17. return true
  18. }
  19.  
  20. scala> val x: MutableInt = 0
  21. x: MutableInt = MutableInt@44e70ff
  22.  
  23. scala> function(x)
  24. res0: Boolean = true
  25.  
  26. scala> x.value
  27. res1: Int = 1
  28.  
  29. val number: Int = numberStream.next
  30.  
  31. var s: Int = 0
  32.  
  33. def function(s: Int): Boolean={
  34.  
  35. var newS = s
  36. newS = newS + 1
  37. s = newS
  38. return true
  39.  
  40. }
Add Comment
Please, Sign In to add comment