To determine the class of a Scala object we use
getClass method. This method returns the Class details which is the parent Class of the instance.
Below is the example to determine class of a Scala object.
Calling method with argument -
Example #1:
Output:
class: class scala.collection.mutable.WrappedArray$ofInt
In above example, Calling the printClass method with parameter demonstrates the class Scala.
Calling method without argument -
Example #2:
Output:
class: class scala.collection.immutable.Nil$
In above example, Calling the printClass method without parameter demonstrates the class Scala.
With additional get* methods -
Example #3:
Output:
person: class Boy
person: Boy
person: Boy
person: Boy
Above code show how the additional get* methods
getName, getSimpleName, and
getCanonicalName work.