Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Is it possible to invoking a method by getting its name in string...
Pankaj Mittal
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I want to invoke a method whose name I've got in
string
.....
2008 SCJP(5.0) 88%
Paul Sturrock
Bartender
Posts: 10336
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can do this sort of thing via
Reflection
. Have a read though that link it should set you on your way.
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Pankaj Mittal
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks buddy !!
I found the solution...
public class Test { public static void main(String args[]) throws Exception { new Test().invoke("Test", "invokeIt"); } public void invoke(String className, String methodName) throws Exception { Class cls = Class.forName(className); System.out.println("class is "+cls.getCanonicalName()); java.lang.reflect.Method method = null; method = cls.getMethod(methodName, new Class[] {}); System.out.println("method name is "+method.getName()); method.invoke(this, null); } public void invokeIt() { System.out.println("invoked"); } }
2008 SCJP(5.0) 88%
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
javax.jms.Message method
Confusion with the below mentioned code
Not able to run sample servlet + jsp
Checking for null inputs
need help urgently
More...