<:<Scala 中的运算符 [英] <:< operator in scala

查看:48
本文介绍了<:<Scala 中的运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提供有关 <:< 在 Scala 中的操作符的一些详细信息.我认为:

Can anybody provide some details on <:< operator in scala. I think:

if(apple <:< fruit)  //checks if apple is a subclass of fruit.

还有其他解释吗?我在 Scala 源文件中看到了很多定义.

Are there any other explanations? I see many definitions in the scala source file.

推荐答案

<:<not an operator - 它是一个 identifier 因此是以下之一:

<:< is not an operator - it is an identifier and is therefore one of:

  • 类型的名称(类、特征、类型别名等)
  • 方法/val 或 var 的名称
  • the name of a type (class, trait, type alias etc)
  • the name of a method/val or var

在这种情况下,<:< 在库中出现两次,一次在 Predef 中作为类,一次作为 Manifest.

In this case, <:< appears twice in the library, once in Predef as a class and once as a method on Manifest.

对于Manifest 上的方法,它会检查this manifest 表示的类型是否是manifest 参数表示的类型的子类型.

For the method on Manifest, it checks whether the type represented by this manifest is a subtype of that represented by the manifest argument.

对于 Predef 中的类型,这是相对较新的,我也对它有点困惑,因为它似乎是相同声明三人组的一部分!

For the type in Predef, this is relatively new and I am also slightly confused about it because it seems to be part of a triumvirate of identical declarations!

class <%<[-From, +To] extends (From) ⇒ To
class <:<[-From, +To] extends (From) ⇒ To
class =:=[From, To] extends (From) ⇒ To

这篇关于&lt;:&lt;Scala 中的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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