-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Miro,
I've done heavy editing to make the quoted post make sense. Forgive me if I have inaccurately portrayed the question. temp temp wrote: > I want a wrapper class for an object. I do not want to write methods > which calls [the superclass] method. Assume I have class. Ok, you want a wrapper class. Generally, this is done like this: public interface Wrapped { int foo(); } public class WrappedWrapper implements Wrapped { private Wrapped _wrapped; public WrappedWrapper(Wrapped wrapped) { _wrapped = wrapped; } public int foo() { return _wrapped.foo(); } } It sounds like you don't want to go through all that trouble to actually implement the methods. > I have [an] interface [which includes the methods] getString(); [and] > getLength(); Some class is implementing this [interface]. At runtime > I want to update this object by overriding method getLength(). One > way is create a new implementation. This implementation is just a > wrapper to actual implementation so in this wrapper I will say > > getLength(){ actualImplementation.getLength(); Right... this is exactly what I have above. > instead of doing this is there a way I create a class override only > method getLength nad rest methods comes from super class . Thanks & > Regards Miro Well... that would be a subclass, not a wrapper class. Often, interfaces and wrappers are accompanied with "adapters" which are implementations of interfaces that don't do anything. They allow you to override some methods and leave the others unchanged. What I'd recommend in your case is a combination of a wrapper and an adapter. In fact, you don't even need another class for the adapter... just use the wrapper itself as the adapter. You can either formally subclass WrappedWrapper to include something specific, or use an anonymous class. Something like this: Wrapped a = ...; // however you want to get this instance WrappedWrapper b = new WrappedWrapper(a) { public int foo() { // overrides WrappedWrapper.foo() doSomethingElse(); } }; You could also look into using the java.lang.reflect.Proxy class, which is super cool and will blow your mind. To answer your original question: no, you cannot change the superclass of a class at runtime. You'll just have to suck it up and write classes like the rest of us. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGMjvN9CaO5/Lv0PARAuLHAJ9RAfmao1PkRu8Wh9GSuhAMPJOa+gCgkmrm ll1PFM1UDLUQASiRDw5z2Jg= =r29/ -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]