title: convert Class object to bytes
body: <p>If I have a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html" rel="noreferrer">Class</a> instance at runtime, can I get its byte[] representation?  The bytes I'm interested in would be in the <a href="http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html" rel="noreferrer">Class file format</a>, such that they'd be valid input to  [ClassLoader.defineClass][3].</p>
  
  <p>[3]: <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html#defineClass(java.lang.String" rel="noreferrer">http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html#defineClass(java.lang.String</a>, byte[], int, int)</p>
  
  <p>EDIT: I've accepted a getResourceAsStream answer, because it's very simple and will work most of the time.  ClassFileTransformer seems like a more robust solution because it doesn't require that classes be loaded from .class files; it would handle network-loaded classes for example.  There's a few hoops to jump through with that approach, but I'll keep in in mind.  Thanks all!</p>