zam zam - 18 days ago 6
Scala Question

Comparing objects using isinstanceOf

I'm trying to use the isInstanceOf operator to get a value from a tuple and checking whether its of a specific type. I'm scratching my head over the error and I don't want to use match cases.

val t = ("ww",2, 3.4)

if(t._1 isInstanceOf[String])
println("yes")


The error I get is:

<console>:1: error: type application is not allowed for postfix operators

Answer

Missing dot .

Corrected

if(t._1.isInstanceOf[String]) println("yes") 
Comments