(Quick Reference)

instanceOf

目的
Purpose

Determines if a domain class instance is an instance of the specified class, resolving the actual class if the instance is a proxy.

使用例
Examples

Given the domain classes:

class Container {
   static hasMany = [children: Child]
}

class Child {
   String name
   static belongsTo = [container: Container]
}

class Thing extends Child {}

class Other extends Child {}

Then you can determine the type of the elements in a Container's children collection using

def container = Container.get(id)
for (child in container.children) {
   if (child.instanceOf(Thing)) {
      // process Thing
   }
   else if (child.instanceOf(Other)) {
      // process Other
   }
   else {
      // handle unexpected type
   }
}

詳細
Description

パラメータ:

Parameters:
  • clazz - the type to check