Re: How to correctly by pass "protected"
From: Chris Uppal (chris.uppal_at_metagnostic.REMOVE-THIS.org)
Date: 01/18/05
- Next message: Dimitrio: "Apache Axis: disabling formatting"
- Previous message: Rogan Dawes: "Re: A class that uses instances of itself? Is this right?"
- In reply to: Roland J Rankin Jr: "Re: How to correctly by pass "protected""
- Next in thread: Chris Uppal: "Re: How to correctly by pass "protected""
- Reply: Chris Uppal: "Re: How to correctly by pass "protected""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 18 Jan 2005 17:30:03 -0000
Roland J Rankin Jr wrote:
> Which I found really surprising. I can change the Child class package
> declaration to match the parent and everything works. but if it's in a
> different package. It refuses to compile.
Maybe I'm misunderstanding the suggestion, but I don't think protected access
works that way. If you have a class Parent, and a subclass Child (in a
different package) then the only way that code in Child can call protected
methods of an instance of Parent, is via an object that is statically known
also to be an instance of /Child/. I.e. it can call:
self.protectedMethod();
or:
super.protectedMethod();
since "self" is statically known to be a Child, but it cannot call:
Child aChild = // ...whatever...
aChild.protectedMethod();
Going back to your problem, there are a few ways that you could evade the
restriction that have not yet been mentioned, using JNI, or doing on-the-fly
bytecode re-writing, for instance. But I don't think that anything makes as
much sense /in the long term/ as getting onto the supplier of this JAR file and
explaining what's broken and getting them to fix it. They will presumably
either agree that its a bug and schedule a fix, or at least explain that you
are doing it wrong and show you how to do it right.
That leaves you with the question of how to get around it in the short term --
don't reject a solution on the basis that it's a kludge, you that don't want to
or can't support it forever. To me, the most reasonable short term
possibilities are to put a simple forwarding class into their package (assuming
it's not sealed) or to use Patricia's suggestion of a reflection-based
workaround.
-- chris
- Next message: Dimitrio: "Apache Axis: disabling formatting"
- Previous message: Rogan Dawes: "Re: A class that uses instances of itself? Is this right?"
- In reply to: Roland J Rankin Jr: "Re: How to correctly by pass "protected""
- Next in thread: Chris Uppal: "Re: How to correctly by pass "protected""
- Reply: Chris Uppal: "Re: How to correctly by pass "protected""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|