Reflection doesn't have anything to do with creating classes, only probing existing ones. You can break some of Java's programming rules by generating bytecode yourself; this might be one of them. Whether such a class is rejected at runtime will depend on to what extent the verifier is invoked on that class, and whether a security manager is installed.
Nope. If i am not mistaken (I could be and correct me if I am wrong on this), but you can't do this even by using CGLIB or by directly using ASM Object web's famous ClassVisitor ... classes have to be non-final.
Anirudh Vyas wrote:
correct me if I am wrong on this
Consider yourself corrected. There's nothing to keep a class file from saying it extends another, final class. Whether or not that class file will be accepted at runtime depends on how closely the JVM is looking at classes, which, in turn, depends on whether the verifier is running, and whether there's a security manager. But as far as defining such a class: of course you can.