>: Null <: 在 Scala 中是什么意思? [英] What is the meaning of >: Null <: in Scala?

查看:39
本文介绍了>: Null <: 在 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 用于类型别名声明,就像 valdef> 用于值和方法声明.在这种情况下,它是一个带有约束的抽象类型别名,因此它是某个 traitclass 的类型成员 - 局部范围内的类型别名不能是抽象的,也不能有限制.

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 IdentAnyRef 的子类型和 Null 的超类型.

Type Ident is a subtype of AnyRef and supertype of Null.

AnyRef

AnyRef 是所有引用类型的祖先,所有类型除了 IntLongChar 等(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 的类型层次结构:

这篇关于&gt;: Null &lt;: 在 Scala 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆