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

前端 未结 6 1799
天涯浪人
天涯浪人 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:30

    xShot.get(0) returns an object; it isn't a variable, so you can't assign to it.

    Also, Integer is immutable (you can't change its value), so you would have to replace the object at position 0 with a new Integer that has the calculated value.

    You can achieve the intention of that line like this:

    xShot.set(0, xShot.get(0) + 5);
    

提交回复
热议问题