Connecting Tech Pros Worldwide Help | Site Map

Reflection: setting public fields of an object from another package

  #1  
Old June 27th, 2008, 05:17 PM
Mikhail Teterin
Guest
 
Posts: n/a
Hello!

I have a method, that is supposed to set fields in an object passed to it.
Any object -- the names of the fields are determined at run-time, the only
(obvious) requirement is, the fields must be "public".

This worked perfectly fine, until I put that method's class into a package
of its own.

Now, when the method is given an object of a class /from another package/
the field-setting fails:

Field CDS_REPL is not accessible: java.lang.IllegalAccessException: Class foo.bar.BarQueue can not access a member of class foo.dang.Meow with modifiers "public"

How can I overcome this? Is there something more permissive than "public",
or, perhaps, I can, somehow, explicitly grant foo.bar.BarQueue the right
to modify public fields the callers?

Thanks!

-mi
Closed Thread