aspose file tools
The moose likes Beginning Java and the fly likes substitute string in methods name? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 8434

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.


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

Joined: Aug 16, 2005
Posts: 12911
    
    3

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: 32651
    
    4
nimo frey wrote: . . .
You would mean "a.get" + what; surely? Maneesh and Jesper have already answered.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: substitute string in methods name?
 
Similar Threads
how to accept an instance of a class as a parameter
String add null to begining
model.addAttribute value won't display using JSTL in my jsp file
jsp:useBean standard action doubt
how to access a session value on JSF page?