ITeye博客

使用StringBuffer变相实现参数的引用传递。

linshenqi · 2010-04-15 10:17 · JAVA · 编程语言 · Markdown

在网上搜了很多资料,多说java没有引用传递,只有值传递。后来发现可以使用StringBuffer变相实现。


void strAppend(StringBuffer str){
  str.Append("world");
}

public static void main(String args[]){
  StringBuffer str = new StringBuffer("hello");
  strAppend(str);
  System.out.println("str=" + str);
}

结果:str=helloworld

其实java的io(nio)还是很强大的,用的好可以大大提高程序运行效率,看来以后有要好好研究下。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。