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

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

    Although xShot.get(0) is a number, it is not a variable. You need to provide a variable for this to work. That said

    int i = xShot.get(0);
    i += 5;
    

    Will not work. i will be incremented by 5, but xShot's object in location 5 is not the same object. You need to get, modify, and set the variable.

    For example:

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

提交回复
热议问题