我的 java 程序遇到了一些问题,我不确定这是否是问题所在,但是在 araylist 内的对象上调用 mutator 方法会按预期工作吗?
例如
public class Account
{
private int balance = 0;
public Account(){}
public void setAmount(int amt)
{
balance = amt;
}
}
public class Bank
{
ArrayList<Account> accounts = new ArrayList<Account>();
public staic void main(String[] args)
{
accounts.add(new Account());
accounts.add(new Account());
accounts.add(new Account());
accounts.get(0).setAmount(50);
}
}
这会按预期工作还是有什么会导致这不?