本文介绍了转让的左手侧必须是一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么不这项工作?
private List<Integer> xShot = new ArrayList<Integer>();
...codes
...codes
...codes
...codes
xShot.get(0) += 5;
不明白为什么一个assignment'isn't的左侧是一个变量。
Can't understand why the left-hand side of an assignment´isn't is a variable..
有人帮忙吗?
推荐答案
如果你只是想通过5来增加和不限于列表&LT;整数GT;
具体而言,你可以说是避免冗长的 xShot.set(0,xShot.get(0)+ 5)
键,而是执行此操作:
If you just want to increment by 5 and aren't limited to List<Integer>
specifically, you could avoid arguably verbose xShot.set(0, xShot.get(0) + 5)
and do this instead:
List<AtomicInteger> xShot = new ArrayList<AtomicInteger>();
xShot.get(0).addAndGet(5);
这将增加的在 xShot.get(0)
5就地事不宜迟。
This will increment the value of the AtomicInteger
in xShot.get(0)
by 5 in-place without further ado.
这篇关于转让的左手侧必须是一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!