2
我如何能延长我有我使用的是使用了鸭子类型类型:型的特点在斯卡拉
type t={
def x:Int
...
}
class t2 {
def x:Int=1
}
def myt:t=new t2 //ducktyping
我想写被迫接口类型特征,但这并不工作:
trait c extends t { //interface DOES NOT COMPILE
def x:Int=1
}
在另一方面:如果我写的性状T1,而不是类型T的话,我失去了鸭子类型特点:
trait t1 {
def x:Int
}
type t=t1
trait c extends t1 { // t1 can be used as interface
def x:Int=1
}
def myt:t=new t2 // DOES NOT COMPILE since t1 is expected
那么我如何使用ducktyping和接口?
谢谢,看起来goo d。 – user1271572 2012-03-15 16:46:43