zoukankan      html  css  js  c++  java
  • Java : 传值or传引用?

    那看看这句经典名言:
    O'Reilly's Java in a Nutshell by David Flanagan (see Resources) puts it best: "Java manipulates objects 'by reference,' but it passes object references to methods 'by value.'"

    1、对象是按引用操纵的
    2、Java 应用程序有且仅有的一种参数传递机制,即按值传递

    按值传递意味着当将一个参数传递给一个函数时,函数接收的是原始值的一个副本
    按引用传递意味着当将一个参数传递给一个函数时,函数接收的是原始值的内存地址,而不是值的副本


    Java passes the references by value just like any other parameter. This means the references passed to the method are actually copies of the original references. Figure below shows two references pointing to the same object after Java passes an object to a method.

    示例:

     public void tricky(Point arg1, Point arg2)  {
        arg1.x = 100;  
        arg1.y = 100;  
        Point temp = arg1;  
        arg1 = arg2;  
        arg2 = temp;  
    } 

    示意图:

  • 相关阅读:
    常见前端面试题CSS部分
    window.location
    实时时间设置
    常用兼容处理
    背景淡入淡出切换
    常用插件
    PHP文件处理函数
    PHP的数据处理函数二(数组)
    php的数据处理函数一(字符串)
    PHP环境搭建(phpstudy)
  • 原文地址:https://www.cnblogs.com/windlaughing/p/3346421.html
Copyright © 2011-2022 走看看