Darshan Darshan - 2 months ago 10
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.)

Ex.
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

Answer

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   
    }
Comments