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

后端 未结 4 1396
天涯浪人
天涯浪人 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:12

    Use this super.fromEntity(entity) to call super class methods.

    As Documentation says:

    In Kotlin, implementation inheritance is regulated by the following rule: if a class inherits many implementations of the same member from its immediate superclasses, it must override this member and provide its own implementation (perhaps, using one of the inherited ones). To denote the supertype from which the inherited implementation is taken, we use super qualified by the supertype name in angle brackets, e.g. super.

    constructor(entity: Entity) : this() {
        super.fromEntity(entity)
    }
    

    To know more read Overriding Rules

提交回复
热议问题