|
Re: Eclipse Class.forname() function [message #1282142 is a reply to message #1281968] |
Tue, 01 April 2014 23:12 |
|
On 04/01/2014 11:33 AM, SIDDHARTH BHARADWAJ wrote:
> I have used class.forname() function for creating objects dynamically in
> eclipse. But for paramaterized constructor i had to class.getconstructor
> function() for which i need to know the datatypes of constructors. So, i
> want to know the way of getting datatypes directly in constructor and
> use them in class.forname() and class.getconstructor().
> This is code which i hv used:
> public class ClassOne {
> public static void main(String[] args) throws ClassNotFoundException,
> NoSuchMethodException, InstantiationException, IllegalAccessException,
> IllegalArgumentException, InvocationTargetException {
> int param1 = 20;
> String className = "ClassTwo";
> Class cl = Class.forName(className);
> Constructor con = cl.getConstructor(int.class);
> Object xyz = con.newInstance(param1);
> System.out.println(((ClassBase)xyz).getA());
> }
> }
Siddharth
This is pretty just a Java reflection question, isn't it? It's got
nothing to do with Eclipse. You might try javaranch.com, jguru.com or
stackoverflow.com. This forum isn't for what you do with Eclipse, but
how you use Eclipse and trouble using it.
Cheers.
|
|
|
Powered by
FUDForum. Page generated in 0.07892 seconds