public class Test {
public String xyz(){
String name="stack";
return name;
}
public static void main(String[] args) {
Test t=new Test();
t.xyz(); //this should stack isn't it??
}
}
该方法的确返回一个值(类型为String
),但是您的代码将其丢弃。
t.xyz(); // This calls the method and discards the return value
如果要查看返回值,请将其分配给变量并打印出来:
String str = t.xyz();
System.out.println(str);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句