Reflecting nonpublic fields

J

Johannes Bialek

Hi,

Is there a possibility to reflect protected fields?

thx for taking some time...

Johannes Bialek
 
C

Chris Smith

Johannes said:
Hi,

Is there a possibility to reflect protected fields?

Sure. Reflection uses access control as intended, so that you can use
reflection for package and protected members within the current package
as well.

If the field is inaccessible normally, see the setAccessible method in
AccessibleObject (which is a base class for Field, Method, and
Constructor). It lets you bypass access control. This is subject to a
check by the SecurityManager to prevent untrusted code from using this
feature to circumvent security checking.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

Is there a possibility to reflect protected fields?

You might wonder how serialisation manages to get at the non-transient
private members via reflection. It uses
AccessController.doPrivileged() to override the general security
privileges
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top