Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var s: Int = 0
- def function(s: Int): Boolean={
- s += 1
- return true
- }
- implicit class MutableInt(var value: Int) {
- def inc() = { value+=1 }
- }
- def function(s: MutableInt): Boolean={
- s.inc() // parentheses here to denote that method has side effects
- return true
- }
- scala> val x: MutableInt = 0
- x: MutableInt = MutableInt@44e70ff
- scala> function(x)
- res0: Boolean = true
- scala> x.value
- res1: Int = 1
- val number: Int = numberStream.next
- var s: Int = 0
- def function(s: Int): Boolean={
- var newS = s
- newS = newS + 1
- s = newS
- return true
- }
Add Comment
Please, Sign In to add comment