Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 213685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:18:08+00:00 2026-05-11T18:18:08+00:00

What exactly is Reflection? I read the Wikipedia article on this subject and I

  • 0

What exactly is Reflection?
I read the Wikipedia article on this subject and I understand that it is a kind of meta-programming, where the program can modify itself at run-time, but what does this mean?
In what kind of situations is this a good approach and when is it the best to use it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:18:08+00:00Added an answer on May 11, 2026 at 6:18 pm

    Reflection is a facility where you can query an object about its attributes at runtime. For example, Python, Java and .Net have facilities where you can find the instance variables or methods of an object.

    An example of an application for reflection is an O/R mapping layer. Some use reflection to construct an object by quering its properties at runtime and dynamically populating an instance. This allows you to do this programatically based on metadata from some sort of data dictionary without having to recompile the application.

    To take a simple example, I’ll use Python because its reflection facilities are very simple to use and involve less boilerplate than those of java or .Net.

    ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
    Python 2.5.2 (r252:60911, Mar 27 2008, 17:57:18) [MSC v.1310 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class foo:
    ...     def __init__(self):
    ...             self.x = 1
    ...
    >>> xx = foo()      # Creates an object and runs the constructor
    >>> xx.__dict__     # System metadata about the object
    {'x': 1}
    >>> a = xx.__dict__ # Now we manipulate the object through 
    >>> a['y'] = 2      # its metadata ...
    >>> print xx.y      # ... and suddenly it has a new instance variable
    2                   
    >>>
    

    Now, we’ve used basic reflection to examine the instance variables of an arbitrary object. The special variable __dict__ on Python is a system property of an object that has a hash table of its members keyed by the variable (or method) name. We have reflectively examined the object and used the reflection facilities to artificially poke a second instance variable into it, which we can then display by invoking it as an instance variable.

    Note that this particular trick doesn’t work on Java or .Net, as the instance variables are fixed. The type system of these languages doesn’t allow new instance variables to be added at runtime in the way that python’s ‘duck’ typing system does. However, you could have reflectively updated the value of an instance variable that was declared in the type definition.

    You can also use reflection to dynamically construct method invocations and perform various other neat tricks such as instantiating an object based on a parameter. For example, if you had some sort of plugin based system where certain capabilities were optional, you could use reflection to query the plugin about what services it offered (perhaps by querying whether certain interfaces were implemented) without requiring explicit metadata.

    Many dynamic language interfaces such as OLE automation use reflection as an integral part of the interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is not exactly reflection, but kind of. I want to make
I have a Java program that uses reflection to find and invoke the main(String[]
I have read this question . I have same issue, but I don't understand
Exactly what the title says. Note, this is not about subscriptable objects.
Exactly that: Does a strings length equal the byte size? Does it matter on
Exactly as the subject, How to create oval button in WPF application?
Exactly when are an Activity 's fields that are annotated with @InjectView or @InjectResource
How exactly can I create a new directory using Emacs? What commands do I
Below is my code to read a doc/docs file. it can read, but the
I am new to reflection and am hitting a brick wall trying to understand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.