简体   繁体   English

Scala泛型类型约束

[英]Scala Generics Type Constraints

I am reading Programming Scala right now. 我正在阅读Programming Scala I just got through the chapter on implicit type conversion, where the <% symbol is introduced. 我刚刚完成了关于隐式类型转换的章节,其中引入了<%符号。 There is also a <: symbol and a < symbol. 还有一个<:符号和一个<符号。

Could someone please summarize the different type constraints? 有人可以总结一下不同的类型限制吗? I am struggling with the difference between <: and < for instance. 我正在努力解决<:<之间的区别。 I am curious if there are any others I haven't covered yet. 我很好奇是否有其他我尚未涉及的其他人。

There is no type constraint called < . 没有名为<类型约束。

A <: B means A is literally a subtype of B (where subtype is defined reflexively, meaning for any type T it is the case that T <: T ). A <: B表示A实际上是B的子类型(其中子类型是自反定义的,对于任何类型T意味着T <: T )。

A <% B means A is either a subtype of B or there is an implicit conversion from A to a distinct type AA for which AA <: B . A <% B意味着A要么是亚型B或存在来自隐式转换A于不同类型AA为其中AA <: B This is called a "view bound." 这称为“视图绑定”。

A >: B means A is supertype of B . A >: B表示AB超类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM