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
。如何修改枚舉傳遞到Java方法
正是在這裏:http://stackoverflow.com/questions/3997518/passing-enums-by-ref-in-java – smas 2011-02-17 15:13:10