为什么不允许System.out.println(super)
?
System.out.println(this);
这没关系,this.toString()
被自动调用和打印。
当然,用实例变量代替 this
也是可以的。
但是,this
和 super
可以按照我所知道的方式使用。
System.out.println(super);
那么为什么会失败呢?我认为它应该隐式调用 super.toString()
。
我已经阅读了 Java 规范文档,但我没有找到原因。
最佳答案
在 http://java.sun.com/docs/books/jls/second_edition/html/syntax.doc.html 检查语法
super
关键字后面必须始终跟有 SuperSuffix,不能为空。
所以 super
永远不能单独作为一个表达式。
关于java - 为什么不允许 System.out.println(super)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6786102/