Darshan Darshan - 1 month ago 7x
Scala Question

Pass different type of value to single function as an arguments in Spark/Scala

I am new in Scala. Can I Pass different type of values to single function as an argument in spark/scala.

I mean Generic function that can access Every type of value as an arguments(ex String,Int,Double etc.)

Here bellow function will accept only Int value.

def Test(firstColumn : Int,secondColumn : Int) : (Int) = {
//My Code here
val FLAG :Int = Test(2,4)

Please suggest me something.

Thanks in advance


You could use type parameters and let Scala infer your return type and not specify a return type like this:

def Test[A,B](firstColumn : A,secondColumn : B) = {
     //My Code here