wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes substitute string in methods name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "substitute string in methods name?" Watch "substitute string in methods name?" New topic
Author

substitute string in methods name?

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I have something like:




you see, the getX is a Method-Name.

Now, I have something like this:




Unfortunately, this does not work. Is there another way to achieve this?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

What are you trying to achieve exactly? Looks like you want to figure out at runtime which method should be invoked. Is that correct?

One way to do it is to get a list of all methods using reflection, iterate through them, get the names, compare the method name with your string and invoke it if required.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Reflection is the way to do this.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
nimo frey wrote: . . .
You would mean "a.get" + what; surely? Maneesh and Jesper have already answered.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: substitute string in methods name?
 
Similar Threads
String add null to begining
how to access a session value on JSF page?
jsp:useBean standard action doubt
model.addAttribute value won't display using JSTL in my jsp file
how to accept an instance of a class as a parameter