Skip to main content
Question Protected by miken32
added 4 characters in body; edited title
Source Link
Joachim Sauer
  • 309.2k
  • 59
  • 567
  • 624

How do I invoke a javaJava method when given the method name as a string?

If I have two variables:

Object obj;
String methodName = "getName";

Without knowing the class of obj, how can I call the method identified by methodName on it?
The

The method being called has no parameters, and a String return value -. It's a getter for a Java bean.

How do I invoke a java method when given the method name as a string?

If I have two variables:

Object obj;
String methodName = "getName";

Without knowing the class of obj, how can I call the method identified by methodName on it?
The method being called has no parameters, and a String return value - a getter for a Java bean.

How do I invoke a Java method when given the method name as a string?

If I have two variables:

Object obj;
String methodName = "getName";

Without knowing the class of obj, how can I call the method identified by methodName on it?

The method being called has no parameters, and a String return value. It's a getter for a Java bean.

added 2 characters in body
Source Link
John Woo
  • 264.5k
  • 70
  • 507
  • 500

If I have two variables:

Object obj;
String methodName = "getName";

Without knowing the class of obj, how can I call the method identified by methodName on it?
The method being called has no parameters, and a String return value - a getter for a Java beana getter for a Java bean.

If I have two variables:

Object obj;
String methodName = "getName";

Without knowing the class of obj, how can I call the method identified by methodName on it?
The method being called has no parameters, and a String return value - a getter for a Java bean.

If I have two variables:

Object obj;
String methodName = "getName";

Without knowing the class of obj, how can I call the method identified by methodName on it?
The method being called has no parameters, and a String return value - a getter for a Java bean.

edited tags
Link
jrudolph
  • 8.4k
  • 4
  • 36
  • 50
Source Link
brasskazoo
  • 79.5k
  • 23
  • 67
  • 77
Loading