不知为什么会提示找不到类?!- package cn.itcast.day1;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.util.Collection;
- import java.util.Properties;
- public class ReflectTest2 {
- public static void main(String[] args)throws Exception{
- InputStream is=new FileInputStream("config.properties");
- Properties pros=new Properties();
- pros.load(is);
- is.close();
- String className=pros.getProperty("className");
- Collection collections=(Collection)Class.forName(className).newInstance();
- ReflectPoint pt1=new ReflectPoint(3,5);
- ReflectPoint pt2=new ReflectPoint(5,5);
- ReflectPoint pt3=new ReflectPoint(3,3);
- ReflectPoint pt4=new ReflectPoint(3,5);
- collections.add(pt1);
- collections.add(pt2);
- collections.add(pt3);
- collections.add(pt4);
- System.out.println(collections.size());
- }
- }
复制代码- className=java.util.arrayList//config.properties
复制代码 |
|