abstract-type

    2热度

    4回答

    我有这样一个类: abstract class CrudResource extends Controller { type ResourceIdType def getAction(id: ResourceIdType) = ... def deleteAction(id: ResourceIdType) = ... ... } 其目的是使用像

    1热度

    2回答

    ,以确保协方差有三种方式实现的协方差: 纯协方差:使用艾菲尔语言, 模拟协方差:使用强制转换和重载 使用F-界多态或虚拟类型 因此,我正在使用虚拟类型测试解决方案,使用scala抽象类型的示例如下: 我们定义3抽象类:图形,节点,边缘 图形类定义2种方法:attachNode(节点)和detachNode(节点) 节点类定义2种方法:attachToGraph(图表)和detachFromGrap

    2热度

    1回答

    可能重复: Scala: Abstract Types vs Generics 章“在Scala编程” 20.6“抽象类型”解释与在所得的以下代码结束使用以举例的抽象类型的: class Food abstract class Animal { type SuitableFood <: Food def eat(food: SuitableFood) } class G

    4热度

    1回答

    scala> class A { type T <: String; def f(a: T) = println("foo")} defined class A scala> (new A).f("bar") <console>:9: error: type mismatch; found : java.lang.String("bar") required: _1.T where v

    8热度

    2回答

    我想围绕抽象和明确的自我类型在斯卡拉我的头。 让我们考虑这个例子: 我想创建一个可扩展的树这么简单一个基地: trait Tree { def children: Iterable[Tree] def descendants: Iterable[Tree] = { val dv = children.view; dv ++ (dv.flatMap { _.children })

    4热度

    1回答

    给出的方法foo下面的代码应该比较操作者明智给定参数bar与lowerBound和upperBound所有是相同的抽象类型Bar的。 trait Foo { type Bar <: Ordered[Bar] val lowerBound: Bar val upperBound: Bar def foo(bar: Bar) = bar >= lowerBoun

    1热度

    1回答

    我很难为我要组装的这个类层次结构制定解决方案。我有一个抽象数据包“Vertex”,以及一个在Vertex实例上运行的抽象类“VertexShader”。实际上,VertexShader的派生类对Vertex的特定派生类进行操作。这很像经典的def eat(f : Food)动物类的例子,但其儿童班只能吃特定种类的食物。 我想问题是,派生顶点类应该提供一个函数“+”在顶点上运行,我需要将此操作的结果

    6热度

    4回答

    我有一个设计模式,其中有一个对象生成器(MorselGenerator及其子),其任何实例总是生成相同的确切类型的对象少量食物和它的孩子),但类型检查员不会让我对这些生成的物体中的两个或多个进行任何操作,相信它们可能会有所不同。 我怎样才能让这个过去的类型检查? trait Morsel { type M <: Morsel def calories : Float

    0热度

    2回答

    我想定义一个抽象类型的抽象递归数据结构。 事情是这样的: case class ParentA(name : String, children : List[ParentA]) extends Parent { type PARENT = ParentA } case class ParentB(name : String, children : List[ParentB]) ex

    11热度

    4回答

    我想使用抽象类型而不是类型参数。 在我的泛型类的构造函数,我想有泛型类型的参数,但代码不编译: class SomeOtherClass(val s: S){ type S } 是“未发现:S型” Scala编译器错误 如果我使用一个类型参数,而不是一个抽象的类型,那么它的工作原理: class SomeClass[T](val t: T){ //... } 是否斯