Hi, In java generics i am trying to load a parametric type using Class.forName() ,but i get an exception 'ClassNotFoundException' below is the code: (i'm using java 7):-
public class MyFixedStack<T>{
MyFixedStack()throws Exception
{
Class<?>c=Class.forName("T");
}
public static void main(String[]ars)throws Exception
{
MyFixedStack<Integer>s=new MyFixedStack<Integer>();
}
}
Hers is the exception thrown :-
Exception in thread "main" java.lang.ClassNotFoundException: T
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at MyFixedStack.<init>(MyFixedStack.java:3)
at MyFixedStack.main(MyFixedStack.java:6)