构建从其父子类,所以我有一个基类:简化斯卡拉
case class CSVRecord (
val timestamp : String,
val transactionId : String,
val action : String,
val fromMSISDN :String,
val toMSISDN :String,
val fromICCID :String,
val toICCID :String,
val finalState :String,
val reason : String,
val source : String
)
而且它有其自身的子类,我偶尔需要与其父的一个实例初始化。有没有更简单的方法来做到这一点?现在我必须重复每个字段并重新分配。在Scala中有更简单/更简洁的方法吗?
class Record (
val id : Long,
val batch_id : Long,
timestamp : String,
transactionId : String,
action : String,
fromMSISDN :String,
toMSISDN :String,
fromICCID :String,
toICCID :String,
finalState :String,
reason : String,
source : String
) extends CSVRecord(timestamp,transactionId,action,fromMSISDN,toMSISDN,fromICCID,toICCID,finalState,reason,source) with KeyedEntity[Long] {
def this() = this(0,0,"","","","","","","","","","")
def this(id : Long, batch_id : Long, r : CSVRecord) = this(id,batch_id,r.timestamp,
r.transactionId,r.action,r.fromMSISDN,r.toMSISDN,r.fromICCID,r.toICCID,r.finalState,r.reason,r.source)
lazy val provisionings : OneToMany[Provisioning] = MWS.recordToProvisioning.left(this)
lazy val batch : ManyToOne[Batch] = MWS.batchToRecord.right(this)
}
'Record' extends'CSVRecord'?这不正好吗? – Mik378
AFAIK你不能扩展一个case类 –
你不能推荐'case class'扩展另一个'case class'(不是这个帖子的情况),因为可能会导致一些平等的奇怪问题。 – Mik378