In Java, how does a post increment operator act in a return statement?

前端 未结 5 1174
忘了有多久
忘了有多久 2020-12-11 14:53

Given the following code, will ixAdd do what you\'d expect, i. e. return the value of ix before the increment, but increment the class member before leaving the function?

5条回答
  •  隐瞒了意图╮
    2020-12-11 15:50

    It does return the value before the increment, and then increment _ix. Therefore the first time you call the method ixAdd on an instance of myCounter it will return 1, the second time it will return 2, and so on.

提交回复
热议问题