Java 方法中,参数的装配顺序

从左到右依次装配,参数的值一旦确定,即使后面修改了该值,方法拿到的值也不会随之变化了。

class Solution {
    public int a;

    @Override
    public String toString() {
        return "Solution{" +
                "a=" + a +
                '}';
    }
}

public class Main{
    static Solution max;
    static Solution change(){
        max = new Solution();
        max.a = 8;
        Solution s = new Solution();
        s.a = 5;
        return s;
    }
    public static void method(Solution x,Solution y){
        System.out.println(x);
        System.out.println(y);
    }
    public static void main(String[] args) {
        max =new Solution();
        max.a=0;
        method(max,change());
    }
}
posted @ 2020-03-02 12:55  断腿三郎  阅读(447)  评论(0编辑  收藏  举报