public class Saiyan extends PlayableFighter {
private boolean transformed;
public Saiyan(....)
{
    :
    :
}

public void isTransformed(boolean x){
transformed=x;

}
public boolean isTransformed(){
    return transformed;
}


}

我认为我的转换后的属性应该是可读写的,但是当我运行测试时却出现此错误

M1PrivateTest.testSaiyanClassWRITEVariables 0/1
   junit.framework.AssertionFailedError
   junit.framework.AssertionFailedError:
   The "transformed" instance variable in
    class Saiyan is a WRITE variable.
    at M1PrivateTest.testSaiyanClassWRITEVariables(Unknown Source) at
      java.util.concurrent.FutureTask.run(FutureTask.java:266) at
       java.lang.Thread.run(Thread.java:745)

最佳答案

改成

public void setTransformed(boolean transformed){
    this.transformed=transformed;
}


按照正常的设置者/获取者模式

10-06 10:21