File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Inherit/modify class at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Inherit/modify class at runtime" Watch "Inherit/modify class at runtime" New topic
Author

Inherit/modify class at runtime

Matti Poro
Ranch Hand

Joined: Dec 03, 2005
Posts: 41


If I load a class that way, is it possible to replace (override) methods in the created object?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

No. It is possible to do it before you load the class using a byte-code manipulation library like BCEL


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

On the other hand, I think I was answering the question you asked, rather than solving the problem you actually have. You can create a proxy object for the object you load, which implements the same interface and/or extends the same base class as your "target" object. In this proxy class, you can implement most of the methods to simply "forward" the call to the target, while others might add code; i.e.,

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inherit/modify class at runtime