scala 有 + 运算符吗? - 03

scala 有运算符吗?this

答案是没有。spa

package com.msym

/**
  * Created by ACER on 2017/7/4.
  */
object Demo {
  def main(args: Array[String]): Unit = {
    println(1 + 2)
    println(1.+(2))

  }
}
打印获得的结果都是 3,

其余的 - ,*, /, %, << 也是这样的,scala

在其余语言中的运算符,以及逻辑操做符,在 scala中都被定义成了方法code

查看其源码:blog

/** Returns the sum of this value and `x`. */
  def +(x: Byte): Int
  /** Returns the sum of this value and `x`. */
  def +(x: Short): Int
  /** Returns the sum of this value and `x`. */
  def +(x: Char): Int
  /** Returns the sum of this value and `x`. */
  def +(x: Int): Int
  /** Returns the sum of this value and `x`. */
  def +(x: Long): Long
  /** Returns the sum of this value and `x`. */
  def +(x: Float): Float
  /** Returns the sum of this value and `x`. */
  def +(x: Double): Double
+ 这个符号实际上是方法的名称,
相关文章
相关标签/搜索