`

Java is Pass-by-Value

阅读更多

This often heard saying is not correct: "primitives are passed by value, and objects are passed by reference"

 

in Java everything is passed by value. Primitives are passed by value, and object references are passed by value. The objects themselves are never passed to a method, but the objects are always in the heap and only a reference(value) to the object is passed to the method.

 

http://stackoverflow.com/questions/40480/is-java-pass-by-reference

 

http://javadude.com/articles/passbyvalue.htm

 

just refer to the following two definitions and maybe you'd find the answer.

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.
分享到:
评论

相关推荐

    Pass by value VS Pass by Reference

    在Java编程语言中,方法调用时参数的传递方式有两种:值传递(Pass-by-Value)和引用传递(Pass-by-Reference)。这两种方式对于理解程序的行为至关重要,尤其是在处理对象时。下面将详细介绍这两种传递方式的工作...

    世界五百强java面试题下载

    - Stack Overflow上的相关讨论:https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value 通过以上分析和扩展阅读,希望能帮助大家更好地理解和掌握Java中对象传递的关键概念。

    servlet2.4doc

    A filter configuration object used by a servlet container to pass information to a filter during initialization. flushBuffer() - Method in interface javax.servlet.ServletResponse Forces any content ...

    Java邮件开发Fundamentals of the JavaMail API

    The Simple Mail Transfer Protocol (SMTP) is defined by RFC 821 . It defines the mechanism for delivery of e-mail. In the context of the JavaMail API, your JavaMail-based program will communicate ...

    Java中带参无返回值方法的使用共4页.pdf.zip

    Java采用传值调用(pass-by-value)机制。这意味着当参数传递到方法时,实际传递的是变量的副本,而不是变量本身。因此,方法内部对参数的修改不会影响到方法外部的变量值。 3. 方法调用: 调用无返回值方法时,只...

    已解决:No 'Access-Control-Allow-Origin'跨域问题

    解决这个问题的方法有很多种,但在Java环境中,特别是使用Tomcat服务器时,一个简洁有效的解决方案是通过配置CORS Filter。CORS(Cross-Origin Resource Sharing)是一种机制,它使用额外的HTTP头部来告诉浏览器允许...

    JSP Simple Examples

    Forms are used to pass user- data to a specified URL which is specified in the action attribute of the form tag. Interface in jsp In interface none of its methods are implemented. All the methods ...

    Effective C++ 中文版

    条款20:宁以pass-by-reference-to-const替换Pass-by-value 条款21:必须返回对象时,别妄想返回其reference 条款22: 将成员变量声明为private 条款23: 宁以non-member、non-friend替换member函数 条款24:若...

    Fortran面试题.pdf

    - **按值传递(Pass-by-value):** 传递的是变量的副本,不会改变原始变量。 - **按引用传递(Pass-by-reference):** 传递的是变量的引用,修改将反映到原始变量上。 2. **接口(Interface)的作用及使用:** ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to ...

    java类、对象、成员、package、import、访问修饰控制符总结

    public class PassByValue { public static void main(String[] args) { int x = 10; change(x); System.out.println(x); // 输出 10,因为按值传递 Integer y = 20; changeRef(y); System.out.println(y); ...

    C Programming

    In this section, the document begins by explaining the fundamentals of computers, which is essential for understanding programming and the context in which C programming operates. It covers: - **...

    tomcat-5.5.23

    Directory used by the JVM for temporary files (java.io.tmpdir) <br>If you do not pass the "-Dcatalina.base=$CATALINA_BASE" argument to the startup command, $CATALINA_BASE will default to the ...

    CE中文版-启点CE过NP中文.exe

    ExecuteCodeEx(Let's you execute code in the target and pass parameters) Added 2 new parameters to getNameFromAddress (ModuleNames and Symbols) Added addModule and deleteModule to the symbollist class ...

    ORACLE转DB2对照全解

    TYPE t1 IS TABLE OF NUMBER INDEX BY PLS_INTEGER; t1_tab t1; ``` **DB2:** ```sql DECLARE t1_tab TABLE(NUMBER) WITH DEFAULT STORAGE; ``` **注意:** Oracle支持基于PL/SQL的表类型,而DB2则提供了一种更...

    2021春招C#.NET笔试题基础篇.pdf

    值传递(pass-by-value)意味着将变量值的副本传递给方法,方法内对参数的修改不影响原变量。引用传递(pass-by-reference)则是将变量的引用地址传递给方法,方法内对参数的修改直接反映到原变量上。 C#中参数传递...

    测试培训教材

    WR-AUTOMATED A test that is executed by WinRunner, Mercury's functional testing tool for Microsoft Windows applications. LR-SCENARIO A scenario that is executed by LoadRunner, Mercury's load ...

    GifDecoder

    * frames as specified by their disposition codes). */ protected void setPixels() { // expose destination image's pixels as int array int[] dest = ((DataBufferInt) image.getRaster().getDataBuffer...

    Python岗位常规面试题.pdf

    print("You cannot divide by zero!") except ValueError: print("Invalid input. Please enter a number.") finally: print("End of program") ``` #### 9. Python中的什么机制实现了元类(Metaclass)?请说明...

    Python文档

    目前市场上的应用软件中有超过一半是面向网络的应用,如数据库服务器、游戏、Java Servlets 和 Applets、CGI 脚本等。数据通信不再是两台机器(本地网络或互联网)之间的奇技淫巧,而是日常生活中不可或缺的一部分。...

Global site tag (gtag.js) - Google Analytics