我使用的是從https://github.com/nekocode/android-parcelable-intellij-plugin-kotlinParcelable派生類在科特林
我這個定義
class ChessClock : TextView {
lateinit var player:String
constructor(context: Context) : super(context)
constructor(context:Context, p:String, angle:Float) : this(context) {
player = p
rotation = angle
}
<snip>
}
和定義改爲
class ChessClock() : TextView, Parcelable {
lateinit var player:String
constructor(context: Context) : super(context)
constructor(context:Context, p:String, angle:Float) : this(context){
player = p
rotation = angle
}
<snip -- various stuff added here>
}
試圖在類的Android Parcelable插件突出顯示了兩個語法錯誤。
在行
class ChessClock() : TextView, Parcelable
TextView
有下劃線與評論「這種類型有一個構造函數,並且必須在這裏初始化。」
在行
constructor(context: Context) : super(context)
super
有下劃線與評論「主構造函數調用的預期。」
我只用了kotlin幾個星期,我不明白這裏發生了什麼。首先,我知道(或至少我認爲我知道)科特林沒有實現多重繼承,所以我不明白是什麼
類ChessClock():TextView的,Parcelable
手段。這真的是合法的kotlin嗎?如何在kotlin中創建派生類Parcelable?
完美。謝謝。 – saulspatz
糟糕。我說得太快了。現在我看到編譯器抱怨聲明'constructor(parcel:Parcel):this()'。該聲明應該如何改變? – saulspatz
我打算讓這個問題成爲一個新問題。 – saulspatz