class EG {
private[this] type TypeMember = A
private[this] var field: Int = 0
}
可以像字段一样为类型成员指定访问修饰符。在OOP的情况下,我们很清楚,领域的encapsulation确实提供了有益于防止意外共享状态和限制状态修改的好处。就我所知,类型成员只能在Scala中找到,而且在很多地方,
这行之有效 class MyClass[T<: Actor: ClassTag] extends Actor {
//....
}
但这并不适当做以下No ClassTag available for MyClass.this.T class MyClass extends Actor {
type T<: Actor
//...
}
即使错误: clas
为什么使用绑定到类值参数的类型成员会生成“类型不匹配”错误?例如: scala> class A { type t }
defined class A
scala> class B(val a: A)
defined class B
scala> val aInt = new A { type t = Int }
aInt: A{type t = Int} = [email prot
我希望我的特质Outer具有两个抽象成员类型Inner1和Inner2。我想Inner2也有抽象成员类型Inner1。我想要求Outer#Inner1等于Inner2#Inner1。什么是最令人信服的方式来做到这一点?到目前为止,我有 trait HaveInner1 {
type Inner1
}
trait Outer {
type Inner1
type
我的情况是这样的: trait A {
type B
def foo(b: B)
}
trait C[D <: A] {
val d: D
def createB(): D#B
def bar() {
d.foo(createB)
}
}
在REPL,它抱怨 <console>:24: error: type mi