Call super class constructor in Kotlin, Super is not an expression

后端 未结 4 1398
天涯浪人
天涯浪人 2020-12-13 03:59

I have two classes Entity and Account as

abstract class Entity(
    var id: String? = null,
    var created: Date? = Date()) {

          


        
4条回答
  •  死守一世寂寞
    2020-12-13 04:38

    You can also move your primary constructor down into the class like this:

    data class Account: Entity {
        constructor(): super()
        constructor(var name: String? = null, var accountFlags: Int? = null): super()
        constructor(entity: Entity) : super(entity)
    }
    

    Advantage of this is, compiler will not require your secondary constructor to call primary constructor.

提交回复
热议问题