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 4571480
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:30:36+00:00 2026-05-21T19:30:36+00:00

i have a problem as : MyFirstClass.java public class MyFirstClass{ String strParam; MySecondClass secClass;

  • 0

i have a problem as :
MyFirstClass.java

public class MyFirstClass{
  String strParam;
  MySecondClass secClass;
  //getters and setters
}

MySecondClass.java

public class MySecondClass{
  String p1Param;
  String p2Param;
  String p3Param;
  String p4Param;
//setters and getters
}

TestClass.java

public void doProcessing(MyFirstClass pObj){
  for(int i=0;i<3;i++){
  System.out.println() ;
  //###question is here
}

I want to use java reflection and call the pObj.getP**Param() methods in for loop by providing the parameters to g

Method m= cls.getMethod("getP"+(i+1)+"Param");
pObj.getSecClass.[ invokeMethod m ]

How it can be made possible.
I don’t want to use array of p*Params.

Thanks in advance.

  • 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-21T19:30:37+00:00Added an answer on May 21, 2026 at 7:30 pm

    Are you sure this is what you need? For me, your code seems to be a typical example of the current trend of abusing reflection for every task. Why don’t you use arrays or maps to store the properties p[0-9]+Param.

    Arrays were invented to do exactly that. They provide a range of variables, indexed by numbers.

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

Sidebar

Related Questions

I have problem with databinding in the Win.Forms DataGridView control. Example: public class A
I have a problem using the Java search function in Eclipse on a particular
I have problem with class design. I have core class for my game objects.
I have problem with refering to special symbol in string: I have: path='C:\dir\dir1\dir2\filename.doc' and
I have problem with date function in php. If I supply string in format
I have problem in C#. I have a list box and a class called
I have problem with deserialize document to object using XmlSerializer class. Code my function
I have problem converting from string to date. The first one i Ok: Date
i have problem with a:visited and a:link for 2 class/id. #title a:link, #title a:visited
I have problem in some JavaScript that I am writing where the Switch statement

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.