string对象是引用类型,为什么又说它是值传递方式呢,而不是引用传递呢?
另外string s=new String ("xyz");创建了几个String Object?它在内存中到底是怎么分配的。
有点搞不懂

解决方案 »

  1.   

    引用传递,编译原理中的call by reference或者pass by reference是专有术语,这里的引用和Java里的“引用类型”中的引用不是相同的概念。
      

  2.   

    java中的参数传递方式确实是“值传递”,对于对象类型,传递的值是所引用对象的地址,所以其实是个引用,理解其原理即可,不要在术语上徘徊。
      

  3.   

    Pass-by-value
        The actual parameter (or argument expression) is fully evaluated and the resulting value is copied into a location being used to hold the formal parameter's value during method/function execution. That location is typically a chunk of memory on the runtime stack for the application (which is how Java handles it), but other languages could choose parameter storage differently.Pass-by-reference
        The formal parameter merely acts as an alias for the actual parameter. Anytime the method/function uses the formal parameter (for reading or writing), it is actually using the actual parameter.