docs: @SuppressWarnings("unchecked")
      public static <T> T asType(Object obj, Class<T> type) {
          if (String.class == type) {
              return (T) InvokerHelper.toString(obj);
          }
  
          // fall back to cast
          try {
              return (T) DefaultTypeTransformation.castToType(obj, type);
          }
          catch (GroovyCastException e) {
              MetaClass mc = InvokerHelper.getMetaClass(obj);
              if (mc instanceof ExpandoMetaClass) {
                  ExpandoMetaClass emc = (ExpandoMetaClass) mc;
                  Object mixedIn = emc.castToMixedType(obj, type);
                  if (mixedIn != null)
                      return (T) mixedIn;
              }
              if (type.isInterface()) {
                  try {
                      List<Class> interfaces = new ArrayList<Class>();
                      interfaces.add(type);
                      return (T) ProxyGenerator.INSTANCE.instantiateDelegate(interfaces, obj);
                  } catch (GroovyRuntimeException cause) {
                      // ignore
                  }
              }
              throw e;
          }
      }