Java按引用传递vs按值传递故障

Java按引用传递vs按值传递故障,java,Java,为什么通过引用传递示例中出现错误obj1.add200really带下划线 public class Test { private int number; Test(){ number = 1; } public static void main(String[] args) { Test obj1 = new Test(); System.out.println("the number is " + obj1

为什么通过引用传递示例中出现错误
obj1.add200really
带下划线

public class Test {

    private int number;

    Test(){
        number = 1;
    }

    public static void main(String[] args) {
        Test obj1 = new Test();
        System.out.println("the number is " + obj1.number);
        System.out.println("the number 1 plus 200 is " + obj1.add200(obj1.number));
        System.out.println("while the number is still " + obj1.number);
        System.out.println("\n");
        System.out.println("the number is " + obj1.number);
        System.out.println("the number 1 plus 200 is " + obj1.add200really(obj1.number));
        System.out.println("while the number is still " + obj1.number);
    }


int add200(int somenumber){
    somenumber = somenumber + 200;
    return somenumber;
}
int add200really(Test myobj){
    myobj.number = 999;
    return myobj.number;
}
}

使用
obj1.add200really(obj1)

因为您没有方法
add200really(int)


您的方法
add200really()
需要一个对象。您试图用
int

@user133466调用它-我不这么认为,因为您不知道基本事实-Java总是按值传递。请阅读此线程-
someObj.func(someObj)
几乎从来都不是正确的做法@用户133466我想你还不明白这个问题,别管解决方案了。