Article View: borland.public.jbuilder.java.language
Article #17939Re: Dynamic object and method invocation
From: Chris Hill
Date: Thu, 24 Sep 1998 00:00
Date: Thu, 24 Sep 1998 00:00
39 lines
1558 bytes
1558 bytes
Given an Object O, a String containing the method name AND an array of the parameter types (Classes): 1) Get the Class of O, call it C 2) Call C.getMethod(method name, array of parameter types) to get a Method object, call it M 3) Call M.invoke(object to call method on, array of parameters) on the Method object So the key methods are: Object.getClass() Class.getMethod(...) Method.invoke(...) If you don't know the parameter types, call Class.getMethods(...) to get a list. On Thu, 24 Sep 1998 10:46:53 -0400, "Ventru" <ventru@diamelle.com> wrote: >Hello: > >I am trying to build a template interpreter, where the template contains the >name of a class and method that needs to be called; ie. >classname.methodname() . My program needs to read the template and then call >the appropriate class and method. I know that I can call a class, but how do >I call a method in that class? > >ie. I have the method name in a string and an Object. How do I call that >method? > >Thank you very much for your help. >Ameet > > > Chris Hill hillca@cs.purdue.edu
Technical Details
Message-ID:
<360a6570.1129885679@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6udm3q$3tn12@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,3e11980aa9f3cc8f X-Google-Attributes: gidf74b3,public From: hillca@cs.purdue.edu (Chris Hill) Subject: Re: Dynamic object and method invocation Date: 1998/09/24 Message-ID: <360a6570.1129885679@forums.borland.com> X-Deja-AN: 394408250 References: <6udm3q$3tn12@forums.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language