The left-hand side of an assignment must be a variable

前端 未结 6 1800
天涯浪人
天涯浪人 2020-12-12 02:06

Why doesn\'t this work?

private List xShot = new ArrayList();
     ...codes
     ...codes
     ...codes
     ...codes
     xSho         


        
6条回答
  •  醉酒成梦
    2020-12-12 02:32

    If you just want to increment by 5 and aren't limited to List specifically, you could avoid arguably verbose xShot.set(0, xShot.get(0) + 5) and do this instead:

    List xShot = new ArrayList();
    xShot.get(0).addAndGet(5);
    

    This will increment the value of the AtomicInteger in xShot.get(0) by 5 in-place without further ado.

提交回复
热议问题