本帖最后由 328078121 于 2013-8-31 19:27 编辑
public class ReflectTest2 {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
InputStream ips = new FileInputStream("config.properties");
//将配置文件读取到流中
Properties props = new Properties();
props.load(ips);//将流中的配置文件加载进来
ips.close();
String className = props.getProperty("className");
Collection collections =
(Collection) Class.forName(className).newInstance();
//这里是怎么和ReflectPoint类的对象联系起来的?
ReflectPoint rpt1 = new ReflectPoint(4,5);
ReflectPoint rpt2 = new ReflectPoint(7,2);
ReflectPoint rpt3 = new ReflectPoint(4,5);
collections.add(rpt1);
collections.add(rpt2);
collections.add(rpt3);
collections.add(rpt1);
System.out.println(collections.size());
}
} |