wood burning stoves 2.0*
The moose likes Java in General and the fly likes Is it possible to extend a final class? (With byte code engineering or whatever) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is it possible to extend a final class? (With byte code engineering or whatever) " Watch "Is it possible to extend a final class? (With byte code engineering or whatever) " New topic
Author

Is it possible to extend a final class? (With byte code engineering or whatever)

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Is it possible in any way to extend a final class? Is there anything i can do to either extend it, or at least mask this?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Have a look at the following link:
class file format
and pay special attention to the access_flags member of the class description structure. If you'd mask (i.e. 'nand') away the ACC_FINAL (0x0010) bit, the class is assumed not to be final. If you 'or' in the ACC_PUBLIC (0x0001) bit, you've automagically turned it into a public class also.
Don't tell anyone I told you, because I don't hack never.
kind regards
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Thanks, but how would this work at runtime? I don't want to change the rt.jat classes before runtime, because I want this to work with any VM and by just running my app (i.e. java myApp). So I can do runtime byte-code engineering, but if System's already defined by the bootstrap loader, can I grab that class def, "nand" the modifier, create a new class extending that, and actually have the VM accept that new class' definition?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to extend a final class? (With byte code engineering or whatever)
 
Similar Threads
Final Class and Class with private constructor
non-overridable methods in JAVA
Java Reflection with final class
final class with java reflection
How can we create our own String class in java?