What is the best way to determine the data type in groovy?
I’d like to format the output differently if it’s a date, etc.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To determine the class of an object simply call:
You can abbreviate this to
someObject.classin most cases. However, if you use this on aMapit will try to retrieve the value with key ‘class’. Because of this, I always usegetClass()even though it’s a little longer.If you want to check if an object implements a particular interface or extends a particular class (e.g. Date) use:
or to check if the class of an object is exactly a particular class (not a subclass of it), use: