Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to check the type of a Scala variable? [duplicate]

Tags:

scala

Is there a simple way to determine if a variable is a list, dictionary, or something else? Basically I am getting an object back that may be either type and I need to be able to tell the difference.

In Python, we have "Type()", "Typeof()" that

scala> val c: String = "Hello world"

Is there any way to determine : Typeof(c) to print : String

like image 431
user3378649 Avatar asked Mar 08 '14 23:03

user3378649


1 Answers

I believe you can just use:

c.getClass
like image 125
user3396298 Avatar answered Nov 04 '22 08:11

user3396298