Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
Scala 重写抽象类型成员 抽象类框{ 键入T_Scala_Generics - Fatal编程技术网

Scala 重写抽象类型成员 抽象类框{ 键入T

Scala 重写抽象类型成员 抽象类框{ 键入T,scala,generics,Scala,Generics,,因为您有权创建交叉点 abstract class Box { type T <: String } type InvariantBox = Box { type T = AnyRef } // compiles abstract class Box2 extends Box { type T = AnyRef //Error:overriding type T in class // Box with bounds <:

,因为您有权创建交叉点

abstract class Box {
    type T <: String
}

type InvariantBox = Box { type T = AnyRef } // compiles

abstract class Box2 extends Box {
    type T = AnyRef //Error:overriding type T in class
                    // Box with bounds <: String; type T 
                    // has incompatible type type T = AnyRef
}
否则,对于任何类型的
A
B
都可以使用B创建类型
A

对于类,有覆盖规则


Scala允许定义没有任何值或只有
null
值的类型。

谢谢你的回答。你能给出一个用null值创建类型的例子吗?用null值创建类型我的意思是
val x:InvariantBox=null
。没有其他
val x:InvariantBox=newbox{type T…}
编译。在Scala规范中,在Dotty中。
type HasT = { type T = AnyRef }
type InvariantBox = Box with HasT