public static <T>T implement(Class<T> type,Object object){
  if (type.isInstance(object)) {
    return type.cast(object);
  }
  return type.cast(Proxy.newProxyInstance(type.getClassLoader(),new Class[]{type},new DuckType(object)));
}

public static < T > T implement ( Class < T > type , Object object ) { if ( type . isInstance ( object ) ) { return type . cast ( object ) ; } return type . cast ( Proxy . newProxyInstance ( type . getClassLoader ( ) , new Class [ ] { type } , new DuckType ( object ) ) ) ; }
causes object to implement the interfacetoimplement and returns an instance of the object implementing interfacetoimplement even if interfacetoimplement was not declared in object . getclass ( ) ' s implements declaration . < p / > this works as long as all methods declared in interfacetoimplement are present on object .
