Is there a difference between x++ and ++x in java?

后端 未结 16 2637
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:34

Is there a difference between ++x and x++ in java?

16条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 03:18

    If it's like many other languages you may want to have a simple try:

    i = 0;
    if (0 == i++) // if true, increment happened after equality check
    if (2 == ++i) // if true, increment happened before equality check
    

    If the above doesn't happen like that, they may be equivalent

提交回复
热议问题