The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Method name as a variable.

Posted by Tarakeswar on August 28, 2001 at 6:51 AM

does anyone know how i can call a method whose name
is determined dynamically? for instance, if i have two

public void method0(){

public void method1(){

and i want to call the method based on the value
of x (without using an if statement), can i do
so? in other words, instead of calling method0()
or method1(), can i call, so to speak, methodx(),
which, if x is 0, will call method0() and, if x
is 1, will call method1()?


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us