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
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: 10384
    
    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: 14156
    
  19

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: 38896
    
  23
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?