@Test public void test() throws Exception { final URLClassLoader loader = new URLClassLoader(new URL[0]); final Class subclass = DynamicSubclass.createSubclass(Blue.class, loader); final Constructor constructor = subclass.getConstructor(long.class); final Blue blue = (Blue) constructor.newInstance(1L); final Class<?> generatedClass = blue.getClass(); assertNotEquals(Blue.class, generatedClass); { assertEquals("blue", generatedClass.getAnnotation(Circle.class).value()); assertEquals("blue()", generatedClass.getConstructor().getAnnotation(Oval.class).value()); assertEquals("blue(long)", generatedClass.getConstructor(long.class).getAnnotation(Oval.class).value()); final Annotation annotation = generatedClass.getConstructor(long.class).getParameterAnnotations()[0][0]; assertEquals("1", ((Triangle) annotation).value()); } { blue.blue(1); assertNotNull(invocation); final Method method = Blue.class.getDeclaredMethod("blue", int.class); assertEquals(invocation.getMethod(), method); assertEquals("1", Join.join(",", invocation.args)); assertEquals("blue", method.getAnnotation(Square.class).value()); assertEquals("blue", ((Triangle) method.getParameterAnnotations()[0][0]).value()); } { blue.green("hello"); assertNotNull(invocation); final Method method = Green.class.getDeclaredMethod("green", String.class); assertEquals(invocation.getMethod(), method); assertEquals("hello", Join.join(",", invocation.args)); assertEquals("green", method.getAnnotation(Square.class).value()); assertEquals("green", ((Triangle) method.getParameterAnnotations()[0][0]).value()); } { blue.red(URI.create("foo: assertNotNull(invocation); final Method method = Red.class.getDeclaredMethod("red", URI.class); assertEquals(invocation.getMethod(), method); assertEquals("foo: assertEquals("red", method.getAnnotation(Square.class).value()); assertEquals("red", ((Triangle) method.getParameterAnnotations()[0][0]).value()); } }
public static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl) { return createSubclass(abstractClass, cl, false); }
DynamicSubclass implements Opcodes { public static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl) { return createSubclass(abstractClass, cl, false); } }
DynamicSubclass implements Opcodes { public static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl) { return createSubclass(abstractClass, cl, false); }  }
DynamicSubclass implements Opcodes { public static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl) { return createSubclass(abstractClass, cl, false); }  static boolean isDynamic(final Class beanClass); static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl); static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl, boolean proxyNonAbstractMethods); static void setHandler(final Object instance, final InvocationHandler handler); static int size(final Type type); static byte[] readClassFile(final Class clazz); static byte[] readClassFile(final ClassLoader classLoader, final Class clazz); static void copyMethodAnnotations(final Class<?> classToProxy, final Map<String, MethodVisitor> visitors); }
DynamicSubclass implements Opcodes { public static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl) { return createSubclass(abstractClass, cl, false); }  static boolean isDynamic(final Class beanClass); static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl); static Class createSubclass(final Class<?> abstractClass, final ClassLoader cl, boolean proxyNonAbstractMethods); static void setHandler(final Object instance, final InvocationHandler handler); static int size(final Type type); static byte[] readClassFile(final Class clazz); static byte[] readClassFile(final ClassLoader classLoader, final Class clazz); static void copyMethodAnnotations(final Class<?> classToProxy, final Map<String, MethodVisitor> visitors); static final String IMPL_SUFFIX; }