@Nullable
  public static <T> T asInstance(Object obj, Class<T> type) {
    return type.isInstance(obj) ? uncheckedCast(obj) : null;
  }
Utility methods applicable to (almost) any object. Includes null-safe variants of methods on class Object.
spock-core/src/main/java/org/spockframework/util/ObjectUtil.java