【问题标题】:Is it possible to change the return value of a method in this case? [closed]在这种情况下是否可以更改方法的返回值? [关闭]
【发布时间】:2016-01-31 10:53:31
【问题描述】:

我想将方法​​ getvalue() 的返回值更改为字符串“消防员”,我从 main 方法尝试过但没有成功。 期待一些解决方案。

public class Summ2 {
private String getValue() {
    return "TUHH";
}

public static void main(String[] args) {
    Summ2 GO = new Summ2();
    assert GO.getValue() == "firefighter";
     System.out.println(GO.getValue());
    }


}

【问题讨论】:

  • 投票结束作为错字/对未来的读者没有价值

标签: java methods return-value


【解决方案1】:

assert 是检查指令,而不是赋值指令。

如果不使用成员变量,您无法从 getValue() 获取新值。

【讨论】:

    猜你喜欢
    • 2014-07-07
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    相关资源
    最近更新 更多