DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Tareq Guest

    reflection and private members


    hi everyone,
    i was testing reflection and used the following code to get fields in the
    jaav.util.Vector class :

    Field[] f= Vector.class.getDeclaredFields();

    for ( int i=0; i < f.length; i++)
    {
    System.out.println(f[i]);
    }

    after executing the code, one of the displayed lines was :

    private static final long Vector.serialVersionUID

    and i could display the value in the field
    serialVersionUID although it is private?? how come this field is displayed
    by reflection api although it is private??

    thanks



  2. #2
    Paul Clapham Guest

    Re: reflection and private members

    You can discover that there is a private field called "serialVersionUID".
    But if you try to use "f[i].get(aVector)" to get the value of that field for
    a particular vector, you will get an IllegalAccessException -- at least, I
    did when I tried it.

    Tareq <shaheen_75@yahoo.com> wrote in message
    news:3998f4e1$1@news.devx.com...
    >
    > hi everyone,
    > i was testing reflection and used the following code to get fields in the
    > jaav.util.Vector class :
    >
    > Field[] f= Vector.class.getDeclaredFields();
    >
    > for ( int i=0; i < f.length; i++)
    >


    > System.out.println(f[i]);
    > }
    >
    > after executing the code, one of the displayed lines was :
    >
    > private static final long Vector.serialVersionUID
    >
    > and i could display the value in the field
    > serialVersionUID although it is private?? how come this field is displayed
    > by reflection api although it is private??
    >
    > thanks
    >
    >




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links