我如何在Java中使用out参数 [英] how i can use out parameter in java

查看:2652
本文介绍了我如何在Java中使用out参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在void中有out参数
作为

无效x(输出字符串z)
{
z ="dd";

}

好的
我怎么能在Java中

感谢您的帮助

in c# has out parameter in void
as

void x(out string z)
{
z="dd";

}

ok
how i can in java

thanks for any help

推荐答案

[<一个href ="http://www.javacamp.org/javavscsharp/outparam.html" target ="_ blank" title ="New Window"> ^ ]可能会对您有所帮助.
this[^] might help you.


Java不支持out参数;所有参数均按值传递,但是参数可以是可变的引用类型,在这种情况下,即使无法实例性修改参数的实例,也可以在函数内部修改对象本身并返回修改后的对象.

请参见: http://www.javacamp.org/javavscsharp/outparam.html [ http://www.javaranch.com/journal/2003/04/immutable.htm [ ^ ].

—SA
Java does not support out parameter; all parameters are passed by value, but a parameter can be of mutable reference type, in this case, even though the instance of a parameter can not be modified referentially, the object itself can be modified inside the function and returned modified.

See this: http://www.javacamp.org/javavscsharp/outparam.html[^]. A primitive or immutable type can be modified as a result of call by wrapping it in a class or passing it as a reference of array (which is a reference type and mutable.

See also about mutable and immutable objects: http://www.javaranch.com/journal/2003/04/immutable.htm[^].

—SA


这篇关于我如何在Java中使用out参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆