Groovy: Determine type of an object
Creating an object called obj of type java.util.ArrayList which implements the java.util.List interface.
instanceof checks if obj is the subclass of some class.
getClass returns the exact type of an object.
examples/groovy/check_type.groovy
def obj = ["question", 42, 'answer'] println obj.getClass() // class java.util.ArrayList println (obj instanceof List) // true println (obj instanceof java.util.ArrayList) // true println (obj.getClass() == List) // false println (obj.getClass() == java.util.ArrayList) // true
Published on 2018-06-01
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post