我想在方法中更改对象的变量y的值,但this.y引用计时器而不是对象
private void move(byte direction) {
Timer projectilemovement = new Timer();
projectilemovement.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
switch (direction){
case 1:
***this.y -= speed;***
break;
}
}
}, 0, 16);
}
this
关键字就可以完成操作,因为y
是一个没有被方法参数或局部变量覆盖的字段。也许我缺少更多信息?