title: Use a class from byte array without reflection?
body: <p>I've instrumented my class using ASM and processed it like this</p>
  
  <pre><code>public class MyClassLoader extends ClassLoader {
  ...
      byte[] classBytes = ... //the class is of type com.mypackage.Test
      Class clazz = defineClass("com.mypackage.Test", classBytes, 0, classBytes.length);
      resolveClass(clazz);
      com.mypackage.Test test =(com.mypackage.Test) clazz.newInstance();
  </code></pre>
  
  <p>However I get ClassCastException on the last line:</p>
  
  <pre><code>java.lang.ClassCastException: com.mypackage.Test cannot be cast to com.mypackage.Test
  </code></pre>
  
  <p>The workaround is to use reflection:</p>
  
  <pre><code>Object test = clazz.newInstance();
  test.getClass().getMethods()[0].invoke(test, null); //invoke some method - successfully
  </code></pre>
  
  <p>Am I using using wrong classloader or something?</p>