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};        
        }
    }

  • 相关阅读:
    Troubleshooting a Jedis Connection Pool Error
    com.mysql.cj.jdbc.exceptions.CommunicationsException
    springboot tomcat连接池
    Spring官方文档
    Troubleshooting-Spring-RestTemplate-Requests-Timeout
    Linux进程和端口命令总结
    Git及GitLab使用手册
    MySQL数据库命令大全
    两天时间,实现自己的 Promise
    vue-cli3.0搭建服务端渲染SSR
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276758.html
Copyright © 2011-2022 走看看