import java.util.*;
import java.text.*;
import java.lang.reflect.*;
public class Test {
String name;
public Test()
{
System.out.println("In Construtor");
}
public Test(String name)
{
this.name=name;
System.out.println("In Construtor paramitarized-----"+name);
}
public int q() {
System.out.println("working");
return 1;
}
public static void main(String args[] ) throws Exception {
Class c=Class.forName("Test");
Test t=(Test)c.newInstance();
t.q();
Constructor cons[]=c.getConstructors();
for(Constructor ci:cons)
ci.newInstance();
Constructor<?> pcon=c.getConstructor(String.class);
pcon.newInstance();
System.out.println(Test.class.getName());
}
}
I was just trying grasp the concepts of Class and ClassLoader Classes.
Now for this line Constructor<?> pcon=c.getConstructor(String.class);
its showing that IllegalArgumentException: why?
Thank you Jon Skeet :) I changed my code with this and its working
Class c=Class.forName("Test");
Test t=(Test)c.newInstance();
t.q();
Constructor<?> pcon=c.getConstructor(String.class);
pcon.newInstance("arijit");
System.out.println(Test.class.getName());
But When I am compiling with -Xlint ,its giving below mentioned warning: Uncheck call getConstructor(java.lang.Class....) as a member of raw type java.lang.Class
What does this mean?