任何人都可以告诉我这种编码语言是什么?它具有与Java类似的结构,但我无法理解。
class Sample {
String student;
@Override
public String toString() {
return "${student}";
}
public static void main(String[] args) {
Sample s = new Sample();
s.student = "Joe"
System.out.println(s.toString())
}
}
答案 0 :(得分:2)
这段代码在groovy中有效...并在标准输出上打印“Joe”。
答案 1 :(得分:0)
这是Java,没有对此进行讨论。
但是2个错误:
class Sample {
String student;
@Override
public String toString() {
return student; //<------------------ and not "${student}"
}
public static void main(String[] args) {
s.student = "Joe"; //<---------------- don't forget ';'
}
}
第一个错误是直观的,我的意思是你可以return "${student};
它会打印它,但它不是用户想要做的,非常确定