zoukankan      html  css  js  c++  java
  • Java 的传值小例子

    public class Test {

        static class B {
            public int i = 0;
            public String s = "0";
        }

        public static void main(String[] args) {
            int i = 0;
            change1(i);
            System.out.println(i);                         //0

            String a = "0";
            change2(a);
            System.out.println(a);                         //0

            B b1 = new B();
            change3(b1);
            System.out.println(b1.i + "   " + b1.s);       //100  100


            B b2 = new B();
            change4(b2);
            System.out.println(b2.i + "   " + b2.s);       //0  0
            
            int[] c1 = new int[]{0};
            change5(c1);
            System.out.println(c1[0]);                     //100
            
            int[] c2 = new int[]{0};
            change6(c2);
            System.out.println(c2[0]);                     //0
        }

        public static void change1(int i) {
            i = 100;
        }

        public static void change2(String a) {
            a = "100";
        }

        public static void change3(B b) {
            b.i = 100;
            b.s = "100";
        }

        public static void change4(B b) {
            b = new B();
            b.i = 100;
            b.s = "100";
        }
        
        public static void change5(int[] c) {        
            c[0] = 100;
        }
        
        public static void change6(int[] c) { 
            c = new int[]{100};        
        }
    }

  • 相关阅读:
    C# 控制反转(IOC: Inverse Of Control) & 依赖注入(DI: Independence Inject)
    英语常见短语汇总001
    ASP.Net Web.config 中引用外部config文件
    CSS样式汇总
    RSA非对称加密算法
    排序算法【2】——快速排序
    cmake引入boost
    boost之algorithm
    tar命令
    欧拉定理
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276758.html
Copyright © 2011-2022 走看看