Avatar of Rookierav

asked on 

Get bean property from bean name in Java

I have a bean with name "MyProps". MyProps bean has a property "ssn".  How to get the property from the bean name? I don't have the reference to the "MyProps" directly.

public class Props {

public class MyProps extends Props {
String a;
double b;
String c;


public class YourProps extends Props {
String d;
String e;
int f;


public class Search {
public static Props googlSrch(String term) {

public static void main (String args[] ) {

Props rtn = googlSrch("getMyProps") ; //MyProps is returned but as a Props
// I want to extract properties a, b, c without casting rtn to MyProps
Props rtn1 =  googlSrch("getYourProps") ; //MyProps is returned but as a Props
//I want to get properties e,f from rtn1

JavaJava EE

Avatar of undefined
Last Comment

8/22/2022 - Mon