delegation - Access problem in java -
I am working with a 3rd party framework and it has come to me that some of these items My classes
square fu {// third party class protected zero method () {}} class FooWrapper Foo extended {private Foo mDelegate; Public FooWrapper (Foo in Delegate) {mDelegate = in Delegate; } Secure zero method () {mDelegate.method (); // error mDelegate}}
problem if I need to assign this method to the internal object but its protected and therefore not accessible is.
Any ideas on ways to solve this particular problem? This is for Java 1.3.
Why are you making a different example of Fu? FooWrapper is already a fu.
class Foo {protected void method () {}} class FooWrapper Foo {protected void method () {extrox; }}
Edit : If you have a different example, use one of the side (albeit a bit ugly though):
< Pre> public square fu {safe method method () {System.out.println ("in foo.method ()"); }} Public Square FooWrapper Foo {private Foo foo; Public FooWrapper (Foo foo) {this.foo = foo; } Public Zero Method () {try {method m = foo.getClass (). GetDeclaredMethod ("Method", blank); M.setAccessible (true); M.invoke (foo, null); } Hold (exception e) {e.printStackTrace (); }}}
Edit2: Depending on your comment below, there are two sub-classes Foo, which only provides public versions of safe mode, and one Which has overridden all the important methods. First one will look like a foo and will work, the other can do anything:
public class Foo {protected void method () {System.out.println ("Foo In. Method () "); }} Public class deltafu fu (public zero method) extends {super.method (); }} Public Square FooWrapper Foo {Personal DelegateFoo Extends Foo; Public FooWrapper (DelegateFoo foo) {this.foo = foo; } Public Zero Method () {foo.method (); / * Additional logic here * /}}
Comments
Post a Comment