Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Private field access through base class

Thread view: 
moop™ - 01 Nov 2005 03:33 GMT
Hi,
I build a base class to read and write private fields of sub-classes,
but bursts IllegalAccessException.

public class BaseClass{
public void read(){
//reflection code

}
public void write(){
// also reflection code
}
}

public class SubClass extends BaseClass{
private String name;
//other methods
}

How can I access the private fields, such as name in SubClass inside
BaseClass?
fsa71@mail.ru - 01 Nov 2005 08:05 GMT
If I understand your question, I think you should create get/set
methods in your BaseClass to access this fields.

-------------------
http://www.excelsior-usa.com/jet.html
JVM based on Ahead-of-Time compilation
Chris Uppal - 01 Nov 2005 09:09 GMT
moopT wrote:

> I build a base class to read and write private fields of sub-classes,
> but bursts IllegalAccessException.
>
> public class BaseClass{
> public void read(){
> //reflection code

Why are you using reflection to access nested classes ?  There can't be any
need for it that I can imagine.

If you are not using reflection to do so, then I think you must be doing
something wrong (that is not visible in your example) since an outer class does
have access to nested classes private members.

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.