[英]What are the alternatives to subtype polymorphism in scala?
我很想知道scala中子类型多态性的完整替代方法。
The basic tools for of achieving statically-checkable polymorphism in Scala are 在Scala中实现静态可检查多态性的基本工具是
Calling all of these 'alternatives' is probably the wrong word, since they are so well integrated. 调用所有这些“替代品”可能是错误的,因为它们是如此完美地集成在一起。 It's not uncommon for some polymorphic algorithms to be expressed by using of several of these tools in conjunction. 一些多态算法通过结合使用这些工具来表达并不罕见。
It's also worth noting the place of for-comprehensions in Scala polymorphism. 值得注意的是Scala多态性中for-comprehension的位置。 For comprehensions don't seem particularly polymorphic. 因为理解似乎并不特别多态。 Below the surface, for-comprehensions are just syntactic sugar for calls to filter/map/flatMap, and implementations of those methods tend to be highly polymorphic. 在表面之下,for-comprehensions只是调用filter / map / flatMap的语法糖,并且这些方法的实现往往是高度多态的。 Thus, what look to be comparatively simple for-loops can result in some really impressive polymorphic effects. 因此,看起来相对简单的for循环可能会产生一些非常令人印象深刻的多态效应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.