Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

need a reflection reminder

Thread view: 
puzzlecracker - 18 Aug 2006 16:41 GMT
I have the name of a  clas.s and the name of the method in it - in a
String format. How to call this method with jdk 1.5.
/**
* params can be null.
*/
public void call(String clazz, String method, String [] params ){


}

Thanks
Oliver Wong - 18 Aug 2006 16:47 GMT
>I have the name of a  clas.s and the name of the method in it - in a
> String format. How to call this method with jdk 1.5.
[quoted text clipped - 4 lines]
>
> }

   http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html

in particular forName(String), getMethods().

   - Oliver
Arne Vajhøj - 19 Aug 2006 00:58 GMT
> I have the name of a  clas.s and the name of the method in it - in a
> String format. How to call this method with jdk 1.5.
[quoted text clipped - 5 lines]
>
> }

Example (from so code I had):

    public static void c(Object o, String methodName, String a, String b) {
        try {
            Class declarg[] = new Class[2];
            declarg[0] = String.class;
            declarg[1] = String.class;
            Method m = o.getClass().getMethod(methodName, declarg);
            Object callarg[] = new Object[2];
            callarg[0] = a;
            callarg[1] = b;
            m.invoke(o, callarg);
        } catch (Exception e) {
        }
    }

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.