错误提示
Exception in thread "main" java.lang.ClassNotFoundException: HashSet
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 ReflectDemo.main(ReflectDemo.java:23)
源码如下:
import java.util.*;
import java.lang.reflect.*;
import java.io.*;
class ReflectDemo {
public static void main(String[] args) throws Exception {
Properties prop = new Properties();
prop.load(new FileInputStream("properties.ini"));
String s = prop.getProperty("className");
Class cl = Class.forName(s);
//System.out.println();
//Set set = (HashSet)cl.newInstance();
//set.add("abc");
//set.add("def");
//set.add("ghi");
//System.out.println(set);
}
}
|
|