我刚刚开始try 使用Kotlin台Android应用程序.我只想继承这样的Application类:
class SomeApp : Application {
}
But the compiler raises the warning:
and suggestion changes it to:
class SomeApp : Application() {
override fun onCreate() {
super.onCreate()
}
}
我读了大约primary and secondary constructors in the docs本.所以,如果超类有一个主构造函数,那么有必要在这里写吗?像应用程序类一样,它有自己的构造函数
public Application() {
super(null);
}
那么就有必要为派生的?或者我不能像Java那样做:
class SomeApp : Application {
constructor SomeApp(){
super();
}
}
or this error suggests something else? Can anyone explain me in detail? I'm very new to the language and this looks weird to me.
编辑:在java中,我可以执行以下操作:class SomeApp extends Application{ }
It has implicit constructor, so I do not have to write: class SomeApp extends Application{ public Application(){ super(); } }
But in kotlin do I have to define empty constructor like the following:
class SomeApp:Application(){ }
?