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

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

    Another option is to create companion object and provide factory method e.g.

    class Account constructor(
            var name: String? = null,
            var accountFlags: Int? = null,
            id: String?,
            created: Date?
    ) : Entity(id, created) {
    
        companion object {
            fun fromEntity(entity: Entity): Account {
                return Account(null, null, entity.id, entity.created)
            }
        }
    }
    

提交回复
热议问题