确定并描述Scala的泛型类型约束 [英] Identify and describe Scala's generic type constraints
问题描述
我见过<:和>:和<%等,有人可以给(或定位)这些描述吗?什么是可能的限制,他们做什么,以及什么时候使用它们的例子?
S <:T
意味着 S
是 T
的子类型。这也被称为上限类型。同样, S>:T
表示 S
是超类型 T
,一个较低的类型绑定。
S <%T
是一个视图边界,表示 S
必须配备查看,将其值映射到类型 T
的值中。
这也让我感到困惑,而且我有一位来自伯克利的编程语言大师。
I've seen "<:" and ">:" and "<%" etc, can someone give (or locate) a good description of these? What are the possible constraints, what do they do, and whats an example of when to use them?
S <: T
means that S
is a subtype of T
. This is also called an upper type bound. Similarly, S >: T
means that S
is a supertype of T
, a lower type bound.
S <% T
is a view bound, and expresses that S
must come equipped with a view that maps its values into values of type T
.
It's confusing for me too, and I have a Masters in programming languages from Berkeley.
这篇关于确定并描述Scala的泛型类型约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!