How to get the type of a variable in Groovy?

In Groovy, you can use the getClass() method to obtain the type of a variable. For example:

def num = 10
println num.getClass()

The output result is:

class java.lang.Integer

If the variable is an object, you can use the getMetaClass().getClass() method to retrieve the type of that object. For example:

def str = "hello"
println str.getMetaClass().getClass()

The output result is:

class java.lang.String
bannerAds