Query regarding Operator Overloading in Scala

0 votes

Hi,

I tried to create a function of "+", so after creating while calling the function showing below error. Could you please help me out?

scala> def +(FirstValue: Int, SecondValue: Int): Int = FirstValue+SecondValue

$plus: (FirstValue: Int, SecondValue: Int)Int

scala> +(2,5)

<console>:24: error: value unary_+ is not a member of (Int, Int)

       +(2,5)

       ^

Jul 10 in Apache Spark by Rachit
10 views

1 answer to this question.

0 votes

All prefix operators' symbols are predefined: +, -, ~, !. The Scala parser treats these symbols at the beginning of expressions always as unary operators regardless of the real presence of corresponding methods "unary_x". But there is a  workaround for this. Refer the below screenshot

image

answered Jul 10 by Karan

Related Questions In Apache Spark

0 votes
1 answer

Which query to use for better performance, join in SQL or using Dataset API?

DataFrames and SparkSQL performed almost about the ...READ MORE

answered Apr 19, 2018 in Apache Spark by kurt_cobain
• 9,240 points
83 views
0 votes
1 answer

Query regarding a spark split logic

First, import the data in Spark and ...READ MORE

answered Feb 9 in Apache Spark by Omkar
• 67,120 points
21 views
0 votes
1 answer

Multidimensional Array in Scala

Multidimensional array is an array which store ...READ MORE

answered Feb 11 in Apache Spark by Omkar
• 67,120 points
63 views
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,110 points
2,047 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,110 points
196 views
0 votes
10 answers

hadoop fs -put command?

copy command can be used to copy files ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Sujay
10,476 views
0 votes
1 answer

Query regarding Appending " to a string in Scala

You can perform this task in two ...READ MORE

answered Jul 10 in Apache Spark by Esha
14 views
0 votes
1 answer

How to create RDD from parallelized collection in scala?

Hi, You can check this example in your ...READ MORE

answered Jul 3 in Apache Spark by Gitika
• 19,720 points
21 views