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

  • Home
  • SEARCH
  • 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 7047631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:47:41+00:00 2026-05-28T02:47:41+00:00

Is there any open source utility or jar for handling reflection in java? I

  • 0

Is there any open source utility or jar for handling reflection in java?

I am passing methods Dynamically to a class and I would like to fetch the return value.

For Example:

class Department {
    String name ;
    Employee[] employees;
    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public  Employee[] getEmployes() {
        return employees;

    }
}

I would like to print all the employees to the console output but instead getting it at run-time like this:

Department dept = new Department();
// add employees..

getEmployeeNames(dept,"getEmployees.getAddress.getStreet");
// So the user says they want employee street, but we don't know that
// until run-tme.

Is there any opensource on reflection to accommodate something like this?

  • 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-28T02:47:42+00:00Added an answer on May 28, 2026 at 2:47 am

    This kind of thing always rings design alarm bells when I see it.

    That being said, I usually think that JXPath ( http://commons.apache.org/jxpath/users-guide.html ) is the most reasonable solution for that type of problem if it can’t be solved in a more engineered way:

    import org.apache.commons.jxpath.JXPathContext;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    /**
     */
    public class JXPather {
        public static void main(String[] args) {
            Department d = new Department();
            d.employees.add(new Employee(new Address("wherever a")));
            d.employees.add(new Employee(new Address("wherever b")));
            d.employees.add(new Employee(new Address("wherever c")));
            d.employees.add(new Employee(new Address("wherever def")));
    
            JXPathContext context = JXPathContext.newContext(d);
            // access matched xpath objects by iterating over them
            for (Iterator iterator = context.iterate("/employees/address/street"); iterator.hasNext();) {
                System.out.println(iterator.next());
            }
    
            // or directly via standard xpath expressions
    
            System.out.println("street of third employee is: "+context.getValue("/employees[3]/address/street"));
    
            // supports most (or all ?) xpath expressions
    
            for (Iterator iterator = context.iterate("/employees/address/street[string-length(.) > 11]"); iterator.hasNext();) {
                System.out.println("street length longer than 11 c'ars:"+iterator.next());
            }
        }
    
        static public class Department {
            List<Employee> employees = new ArrayList<Employee>();
            public List<Employee> getEmployees() {
                return employees;
            }
        }
    
        static public class Employee {
            Address address;
            Employee(Address address) {
                this.address = address;
            }
            public Address getAddress() {
                return address;
            }
    
        }
    
        static public class Address {
            String street;
            Address(String street) {
                this.street = street;
            }
            public String getStreet() {
                return street;
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any open source Object Database available? I would like to have a
Are there any open-source tools available which support searching for Java methods by the
Are there any open source or commercial web programming language that function much like
Is there any open source Object to XML serializer in Java that uses writeObject
Is there any Open Source Voice Recognization Library in Java?
Is there any open source library available meant for image filtering effects(like fisheye, old
Is there any open-source threat modeling tool - sort of like SDL Threat Modeling
Possible Duplicate: Good STL-like library for C Are there any open source C libraries
Are there any open-source libraries that all programmers should know about? I'm thinking something
Is there any open source OCR library written in .NET, or written in any

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.