The difference between == and === in Scala, Spark

I am from Java and new to Scala.

I use Scala and Spark. But I can not understand where I use == and === .

Can someone tell me in which scenario I need to use these two operators, and what is the difference between == and === ?

+21
source share
3 answers

" == " uses equals methods that check if two references point to the same object. The definition of " === " depends on the context / object. For Spark, " === " uses the equalTo method. Cm

(Because you are referring to Spark :) An important difference between Spark is the return value. For a column:

  • == returns boolean

  • === returns a column (which contains the result of comparing elements from two columns)

+25
source

Generally speaking, these are just functions.

For different types, "==" and "===" can be defined or "overloaded" for different values.

For example, in some test environment, "===" is defined for some special function. Cm. .

+9
source

ScalaTest allows you to use the Scala statement syntax, but defines the triple equals (===) operator to give you better error messages. The following code will give you an error indicating only that the statement has failed:

assert (1 == 2) Instead, using triple equals, you get a more informative error message: "1 is not equal to 2":

assert (1 === 2)

Check out this page for more details. What is the === operator (triple equivalent) in Scala Koans?

0
source

All Articles