This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Index of functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Index of functions" Watch "Index of functions" New topic

Index of functions

Vinicius Souza
Ranch Hand

Joined: May 18, 2011
Posts: 45

Hi! I need something similar to a vector of functions so I can call that function using its index.. Is it possible in Java ? Today my test engine is doing somehing like that:

But its ugly and ineficient, how can I bypass this uglyness?

Thans in advance!

Java is the best (I love C too) heehhh
Jayesh A Lalwani

Joined: Jan 17, 2008
Posts: 2272

Do all methods take the same parameters?

You can use Reflection to populate an array of Method objects
Or you can do something like this

Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

The Java equivalent of a "function" is an object which implements the Runnable interface, if you don't want the function to return anything. If you want the function to return something of type V, let's say, then you need an object which implements the Callable<V> interface. You can put such objects, like any other objects, into an array or a List or a Map, whichever works better for you.
subject: Index of functions
Similar Threads
Is possible change icon of Ok's botton in JOPtionPane, How?
Do while error, I'm going crazy
Bytearray to ascii string? Remove padding?
Need Suggestion
How to change the method names dynamically using for Loop ?