本帖最后由 漫步人 于 2013-10-23 19:45 编辑
- public class ReflectTest {
- //config.properties文件的中clsassName=java.util.ArrayList
- public static void main(String[] args)throws Exception {
-
- //反射的实际应用
- InputStream ips= new FileInputStream("config.properties");
- Properties prps= new Properties();
- prps.load(ips);
- ips.close();
- String className= prps.getProperty("className");
- System.out.println(className+"为什么显示null");
- Collection collections =(Collection) Class.forName(className).newInstance();//26行报错
- PeflectPoint pt0= new PeflectPoint(3,5);
- PeflectPoint pt2= new PeflectPoint(3,4);
- PeflectPoint pt3= new PeflectPoint(3,3);
- collections.add(pt1);
- collections.add(pt2);
- collections.add(pt3);
- System.out.println(collections.size());//空指针异常
复制代码 |