【问题标题】:The value of a variable does not get updated when I pass that to a method to do so? [duplicate]当我将变量的值传递给方法时,变量的值不会更新吗? [复制]
【发布时间】:2015-03-19 15:50:46
【问题描述】:
package com.mkyong.test;

public class Main {

    public static void main(String[] args) {
        String something = "";
        callSomething(something);

        System.out.println(something);
    }

    private static String callSomething(String something) {
        something = "Hello Wrold !";
        return something;
    }
}

【问题讨论】:

标签: java variables static scope main


【解决方案1】:

不,在方法中,您正在更改局部变量的引用。

将您的方法调用更改为:

something = callSomething(something);

【讨论】:

    猜你喜欢
    • 2023-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 2017-02-28
    • 2018-10-06
    • 1970-01-01
    相关资源
    最近更新 更多