如果我有一个像下面这样的课程:
public class Foo()
{
private RandomObject randomObject = new RandomObject();
public RandomObject GetRandromObject()
{
return randomObject;
}
}
在另一堂课中,我这样做:
public class Goo()
{
private Foo fooObject = new Foo();
public Goo()
{
RandomObject ro = fooObject.GetRandomObject();
ro.ChangeNumberVariable(23);
}
}
会fooObject
改成randomObject
NumberVariable
23吗?
如果不是,我是否只需要Foo
调用一个方法SetRandomObject
并传入ro
?这会是 Java 中通过引用传递的一个很好的替代品吗?
如果我这样做怎么办:
public class Goo()
{
private Foo fooObject = new Foo();
public Goo()
{
fooObject.GetRandomObject().ChangeNumberVarialbe(23);
}
}
它仍然没有改变NumberVariable
吗?