2011-04-15 43 views
3

我對Scala很陌生,我正嘗試在Lift中使用lift-squeryl記錄。 Scala是2.8.1,Lift是2.3。我的問題是我想使用Record中的(Mega)ProtoUser,但它與lift-squeryl記錄相沖突。是否可以將基類的Scala方法重命名?

我跟着的指令:

lift-squeryl-record example

它沒有使用ProtoUser,並試圖定義我的用戶是這樣的:

trait AbstractUser[MyType <: AbstractUser[MyType]] extends 
ProtoUser[MyType] with Record[MyType] with KeyedRecord[Long] { 

NB:KeyedRecord是從包net.liftweb .squerylrecord,不是net.liftweb.record

然後我得到以下錯誤:

overriding lazy value id in trait ProtoUser of type net.liftweb.record.field.LongField[MyType]; method id in trait KeyedRecord of type => Long needs倍率」 modifier`

因爲無論KeyedRecord和ProtoUser定義一個不同的標識方法。既然我不控制任何類/特徵的代碼,是否有任何「Scala」的方式,比如重命名其中一種方法?我真的不想在兩者之間做出選擇。 :(

回答

3

不,你不能在子類中重命名方法。如果有來自母體的類型兩個相互矛盾的方法簽名,則需要訴諸其他方式,如通過委託間接(http://en.wikipedia.org/wiki/Delegation_pattern

trait AbstractUser[MyType <: AbstractUser[MyType]] extends ProtoUser[MyType] { 
    def record: Record[MyType] with KeyedRecord[Long] 
} 
相關問題