package cn.itcast.day1;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;
public class ReflectTest2 {
/**
* @param args
*/
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
//实际开发中不能用相对路径,只能用绝对路径:getRealPath();
InputStream ips=new FileInputStream("config.properties");
Properties prop=new Properties();
prop.load(ips);
ips.close();
String className=prop.getProperty("className");
Collection collections=(Collection)Class.forName(className).newInstance();
//Collection collections=new HashSet();
ReflectPoint rp1=new ReflectPoint(3,3);
ReflectPoint rp2=new ReflectPoint(3,4);
ReflectPoint rp3=new ReflectPoint(3,5);
ReflectPoint rp4=new ReflectPoint(3,3);
collections.add(rp1);
collections.add(rp2);
collections.add(rp3);
collections.add(rp4);
collections.add(rp1);
System.out.println(collections.size());
}
}
最简单的框架(配制文件config.properties)文件内容:className=java.util.ArrayList
最新推荐文章于 2020-05-01 22:28:12 发布