我现在正在研究Java项目。我有两个主要问题,我必须知道答案。
使用通过参数传递的对象时,传递的对象是否可以用作指向原始对象的指针,如:
public void DoThis(Object That) {
That.function(10, 100); // Let's just say this raises 10 to the power of 100, I know this function works as it's part of the original Object.
That = new Object(); // I want to know if this changes anything in the original Object or if the passes "That" Object I use is a reference or copy of some sort.
}
另一个问题是,如果我将一个本地对象设置为等于另一个已经存在的对象,然后将该对象设置为一个不同的对象或一个新的对象,如果它改变了我设置为等于的第一个对象,如:
public void DoThisOtherThing(Object That, boolean Maybe) {
Object Thing = That.getSub();
if (Maybe)
Thing = Thing.getSub(); // I want to know if this would change That.getSub();
else
Thing = new Object(); // I want to know if this would also change That.getSub(); I would imagine if the other case doesn't, this wouldn't, and vice versa
That.getSub().setValue(Thing.getValue());
}
我对C更加熟悉,对我来说更直接了。 Java有许多事情由Java Runtime在后台自动处理,并且不知道它到底在做什么。我通常不使用Java,但是对于我正在从事的这个项目,我需要这样做。先感谢您! :)