public class Test {
private Result result;
public Test(Result res){
this.result = res;
}
public void alter(){
this.result = Result.FAIL;
}
}
public enum Result{ PASS, FAIL, MORE};
public Result myResult = Result.PASS;
Test test = new Test(myResult);
test.alter();
在上面的示例中,我将如何修改方法myResult
内的变量alter
?由于 Java 是按值传递的,因此该示例只是将其值分配给this.result
.