类似于以下内容:
参考示例:
void changeString(ref String str) {
str = "def";
}
void main() {
String abc = "abc";
changeString(ref abc);
System.out.println(abc); //prints "def"
}
Run Code Online (Sandbox Code Playgroud)
例子:
void changeString(out String str) {
str = "def";
}
void main() {
String abc;
changeString(out abc);
System.out.println(abc); //prints "def"
}
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,updateWithContex返回作为参数的相同对象是否真的是不好的做法?
class SomeClass{
Foo updateWithContex(Foo foo){
foo.setAppId(i);
foo.setXId(index);
//.....
return foo;
}
}
class Foo{
public void setAppId(int appId)
{
//
}
public void setXId(int appId)
{
//
}
public void changeState(X x)
{
//
}
}
Run Code Online (Sandbox Code Playgroud)
在C++中,我看到过这样的代码:
BigObject&
fastTransform( BigObject& myBO )
{
// When entering fastTransform(), myBO is the same object as the function
// argument provided by the user. -> No copy-constructor is executed.
// Transform myBO in some way
return myBO; // Transformed myBO …Run Code Online (Sandbox Code Playgroud)