how do I increment an integer variable I passed into a function in Scala?

后端 未结 5 1415
深忆病人
深忆病人 2021-01-18 05:34

I declared a variable outside the function like this:

var s: Int = 0

passed it such as this:

def function(s: Int):         


        
5条回答
  •  借酒劲吻你
    2021-01-18 05:52

    If you just want to increment a variable starting with 3

    val nextId = { var i = 3; () => { i += 1; i } }

    then invoke it:

    nextId()

提交回复
热议问题