正如@Kon在他的评论中提到的,
Java中的一个空构造函数包含对超类构造函数的隐式调用.
此外,没有明确调用super()的非空构造函数将在顶部具有隐式调用.
离开super()调用是唯一的时候,如果你打算使用参数自己调用一个不同的超类构造函数.
更新:考虑以下代码,它说明了离开eclipse生成的super()是错误的情况.
public class Foo{
public Foo(int a, int b) {
System.out.println("Foo constructor with-args is called");
}
public Foo() {
System.out.println("Foo with no-args is called");
}
}
class Bar extends Foo {
public Bar() {
// Implicit call to super()
super();
// Explicit call to super(a,b);
// This will not compile unless the call above has been removed.
super(1,2);
}
}