reflection and private members


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: reflection and private members

  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
    >
    >




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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center