2012-03-21 61 views
1

好吧,我知道Scala allwos沒有輔助類型參數。如果我有一個像Scala aux cons類型參數解決方法

class Group[G <: Groupable] (groupees: Buffer[G]) { 
    //stuff here 
} 

,如果我想擴展該類什麼一類,在這裏說

class Lizards extends Group [Lizard] (Buffer[Lizard]()) 

父類的利弊爭論似乎沒有必要,所以我希望把它記下來假設如果Group參數化了某些東西,應該在緩衝區創建中使用該類型。有沒有辦法做到這一點,除了禁止類型的輔助缺點?

回答

3

似乎爲我工作的罰款:

import collection.mutable.Buffer 
trait Groupable 
class Group[G <: Groupable] (groupees: Buffer[G]) 
class Lizard extends Groupable 
class Lizards extends Group[Lizard] (Buffer()) // type only on superclass 
class Lizards extends Group (Buffer[Lizard]()) // type only on argument 
+0

weeeeeeeeeeeeeeeeeeell,這是一半的方式通過))))))將有雖然經過一段時間來接受這個現實! – noncom 2012-03-21 17:02:01