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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 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: 9995
    
    7

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: 13884
    
  10

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: 36599
    
  16
nimo frey wrote: . . .
You would mean "a.get" + what; surely? Maneesh and Jesper have already answered.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: substitute string in methods name?
 
Similar Threads
jsp:useBean standard action doubt
how to accept an instance of a class as a parameter
model.addAttribute value won't display using JSTL in my jsp file
how to access a session value on JSF page?
String add null to begining