Overriding a method in statically created objects
Posted
by I82Much
on Stack Overflow
See other posts from Stack Overflow
or by I82Much
Published on 2010-05-26T19:07:49Z
Indexed on
2010/05/26
19:11 UTC
Read the original article
Hit count: 250
All,
Due to a bug in a library I'm using, I need to override the dispose() method on all objects extending a certain class and make it a NO-OP. I know that if I'm making new instances of the classes directly, this is easy to do:
layerManager = new LayerManagerLayer(wwd) {
@Override
public void dispose() {}
};
The problem is that a lot of the object instances I get are not directly constructed by my client code, but instead are created via static library method calls.
// Here I want to override the dispose method, but I cannot.
Layer l = ShapefileLoader.makeShapefileLayer(this.getClass().getResource("polylines10.shp"));
Is there a way I can inject my dispose method into that statically created object without modifying the original sourcecode?
© Stack Overflow or respective owner