The problem is your mapObj
is of type Map[Any,Any]
and hence mapObj("Add")
returns element of type Any
(which actually is Function2). Hence the compiler does not let you use it as function. You need to convert it to Function2 and then use it.
scala> val mapObj = Map(1->'a',"Add"->((x:Int,y:Int)=>(x+y)))
mapObj: scala.collection.immutable.Map[Any,Any] = Map(1 -> a, Add -> <function2>
)
scala> mapObj("Add")
res8: Any = <function2>
scala> mapObj("Add").asInstanceOf[scala.Function2[Int,Int,Int]](1,2)
res9: Int = 3
To avoid all this, it is rather recommended that you exclude 1->'a'
from your map and just have the map as type Map[Int, Function]