On Nov 7, 3:53 pm, Prashant <[email protected]> wrote:
> Hi,
>
> Suppose, I have a list of Qualified Names of a set of classes (say, in a
> property or text file) and I want to call a method (pre-decided), from one
> of the listed class, when required. Is there any way to do that? My
> knowledge of java says NO, if you have any idea please reply.

If it has an accessible default constructor:
Class.forName("my.class.Name").getConstructor().newInstance()
otherwise you'll need to pass in the constructor arguments types and
the arguments itself

Don't use:
Class.forName("my.class.Name").newInstance()
although shorter it propagates any exception thrown by the
constructor, including checked ones. You don't want this.

Cheers
Philippe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to