在 Scala 中,赋值运算符是“="吗?方法调用? [英] In Scala, is assignment operator "=" a method call?

查看:32
本文介绍了在 Scala 中,赋值运算符是“="吗?方法调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Scala 书籍,在 Scala 中编程" -

As per Scala book, "Programming In Scala" -

Scala 是一种纯形式的面向对象语言:每个值都是一个对象,每个操作都是一个方法调用.例如,当您在 Scala 中说 1 + 2 时,您实际上是在调用 Int 类中定义的名为 + 的方法.

从这个意义上说,使用="运算符的赋值操作怎么样?这也是一种方法吗?似乎不太可能,因为它必须存在于所有类或所有类都必须从其继承的某些公共超类(例如 java.lang.Object ?)中.或者是不是所有的操作都是 Scala 中的方法调用?

In that sense, what about assignment operation using "=" operator? Is that also a method? Seems unlikely, because then it has to be present in all classes or some common super class (say, java.lang.Object ?) that all classes have to inherit it from. Or is it that not all operations are really method calls in Scala?

推荐答案

不.赋值运算符 (=) 是保留字.还有以下内容:

Nope. Assignment operator (=) is a reserved word. Also the below are:

_ : = => <- <: <% >: # @

_ : = => <- <: <% >: # @

有关更全面的列表,请参阅§ 1.1.关于 = 的更多信息在 § 6.12.4 中有描述.

For a more comprehensive list refer § 1.1. Some more information regarding = is described in § 6.12.4.

所以是的,它不是方法调用.

So yes it is not a method call.

这篇关于在 Scala 中,赋值运算符是“="吗?方法调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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