请教:怎样函数里改变一个Double变量的值?# Java - 爪哇娇娃
h*y
1 楼
我想在函数里改变一个Double变量的值,可是这下面的函数始终打印2.0而不是0.3。好
像java是新创建了一个对象,而不是去改变原来对象的值。请问各位大牛,怎样修改一
个Double 变量的值啊?多谢拉!!!
public class test {
public static void main(String [] args){
Double dObj = new Double(2.0);
test tt=new test();
tt.change(dObj);
System.out.println("Double " + dObj);
}
public void change(Double dObj) {
dObj = 0.3;
}
}
像java是新创建了一个对象,而不是去改变原来对象的值。请问各位大牛,怎样修改一
个Double 变量的值啊?多谢拉!!!
public class test {
public static void main(String [] args){
Double dObj = new Double(2.0);
test tt=new test();
tt.change(dObj);
System.out.println("Double " + dObj);
}
public void change(Double dObj) {
dObj = 0.3;
}
}