Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Generics 尝试将参数化或抽象类型构造函数视为其上限时出现Scala类型不匹配错误_Generics_Scala_Types - Fatal编程技术网

Generics 尝试将参数化或抽象类型构造函数视为其上限时出现Scala类型不匹配错误

Generics 尝试将参数化或抽象类型构造函数视为其上限时出现Scala类型不匹配错误,generics,scala,types,Generics,Scala,Types,简化示例: trait WithUpperBounds[AA[_] <: Set[_], Node, Edge] { val nodes: AA[Node] val edges: AA[Edge] } class WithoutUpperBounds[AA[_] <: Set[_], Node, Edge]( val nodes: AA[Node], val edges: AA[Edge] ) extends WithUpperBounds[AA,

简化示例:

trait WithUpperBounds[AA[_] <: Set[_], Node, Edge] {
    val nodes: AA[Node]
    val edges: AA[Edge]
}

class WithoutUpperBounds[AA[_] <: Set[_], Node, Edge](
    val nodes: AA[Node],
    val edges: AA[Edge]
) extends WithUpperBounds[AA, Node, Edge] {
    val nodes2Set: Set[Node] = nodes
    val edges2Set: Set[Edge] = edges
}

trait with upperbounds[AA[]将Seq[;]描述中的通配符更改为:

class WithoutUpperBounds[AA[_] <: Seq[_ <: Node], B <: Node](val nodeSeq: AA[B]) extends WithUpperBounds[AA, B] {

class without upperbounds[AA[\p>@thoredge为我指明了正确的方向。我在Predef.scala中找到了解决方案:

type Set[A] = collection.immutable.Set[A]
通配符丢弃了类型等价性,但您可以在不声明的情况下对任意参数进行抽象。我的特征现在看起来像:

trait WithUpperBounds[AA[B] <: Set[B], Node, Edge]…

trait with upperbounds[AA[B]Thx!实际上,我正在使用不同的不相关类型实例化我的类型构造函数。我修改了我的示例以更好地表示我的具体场景。我怀疑我误解了与更高类型相关的上界。
trait WithUpperBounds[AA[B] <: Set[B], Node, Edge]…