我定义了一个Point
类:
public class Point {
...
public String toString() {
return "abc";
}
}
以及应该注意没有人覆盖其toString()
方法的一个方面:
declare error
: execution(public String Point+.toString()) && !execution(public String Point.toString())
: "Forbidden execution operation!";
declare error
: call(public String Point+.toString()) && !call(public String Point.toString())
: "Forbidden call operation!";
然而,当输入以下代码时,没有任何错误标记:
class Point4 extends Point {
public Point4(int x, int y) {
super(x, y);
}
@Override
public String toString() { //I'd be expecing a compilation error here.
return super.toString();
}
}
public class Main {
public static void main(String[] args) {
Point4 p = new Point4(2, 3);
System.out.println(p.toString()); //I'd be expecting a compilation error here
}
}
我究竟做错了什么?
谢谢