Results 1 to 2 of 2
  1. #1
    JavaForums's Avatar
    JavaForums is offline Administrator
    Join Date
    Dec 2006
    Posts
    854
    Rep Power
    10

    Default Reflection example - accessing private data

    If you think that you cannot access private data members of a class from some other class, then think again. With Reflection, this is possible.
    (more…)

  2. #2
    alchemist is offline Member
    Join Date
    Sep 2009
    Posts
    6
    Rep Power
    0

    Default

    Yes you can see private class variables you need use: myobject.getClass().getDeclaredFields()

    NOT

    myobject.getClass().getFields()

    Using getDeclaredFields reveals all class vars, getFields() only reveals publicly accessible vars

    Here's a good example of these call in use: http://bytearray.brixtonjunkies.com/2009/09/24/auto-object-population-via-reflection/

Similar Threads

  1. [SOLVED] Accessing private constructor
    By piyu.sha in forum New To Java
    Replies: 2
    Last Post: 10-06-2008, 05:45 AM
  2. Axis Client accessing data on .Net webservice
    By cfacile666 in forum Web Frameworks
    Replies: 3
    Last Post: 09-02-2008, 11:35 AM
  3. simple question about private data
    By littleBean in forum New To Java
    Replies: 12
    Last Post: 07-02-2008, 04:09 PM
  4. Accessing Data from a .txt file
    By Oasis13 in forum New To Java
    Replies: 5
    Last Post: 02-01-2008, 12:16 AM
  5. Packaging and accessing data files
    By todd in forum Advanced Java
    Replies: 1
    Last Post: 08-01-2007, 12:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •