>: Null <: 在 Scala 中是什么意思? [英] What is the meaning of >: Null <: in Scala?
问题描述
我找了很多,都没有找到,Scala中这种类型声明
是什么意思?
I searched a lot, but I didn't find anything, What is the meaning of this type of type declaration
in Scala?
type Ident >: Null <: AnyRef
推荐答案
Keyword type
用于类型别名声明,就像 val
和 def
> 用于值和方法声明.在这种情况下,它是一个带有约束的抽象类型别名,因此它是某个 trait
或 class
的类型成员 - 局部范围内的类型别名不能是抽象的,也不能有限制.
Keyword type
is for type alias declaration, just like val
and def
are for value and method declaration. In this case it's an abstract type alias with constraints, so it's a type member of some trait
or class
- type alias in local scope can't be abstract and can't have constraints.
Type Ident
是 AnyRef
的子类型和 Null
的超类型.
Type Ident
is a subtype of AnyRef
and supertype of Null
.
AnyRef
AnyRef
是所有引用类型的祖先,所有类型除了 Int
、Long
、Char
等(Java 原语).
AnyRef
is an ancestor of all reference types, all types except Int
, Long
, Char
and so on (Java primitives).
空
Null
是所有可为空"类型的子类型.事实上,它是所有引用类型的子类型.
Null
is subtype of all "nullable" types. In fact it's a subtype of all reference types.
因为所有 AnyRef
都是可以为空的,所以 >: Null
的唯一附加约束是 Ident
不是 Nothing
>.
Since all AnyRef
are nullable the only additional constraint from >: Null
is that Ident
is not Nothing
.
参见 Scala 的类型层次结构:
这篇关于>: Null <: 在 Scala 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!