Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inherit/modify class at runtime  RSS feed

 
Matti Poro
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If I load a class that way, is it possible to replace (override) methods in the created object?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. It is possible to do it before you load the class using a byte-code manipulation library like BCEL
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.,

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!