- 张孝祥反射疑问:
- public class ReflectTest3 {
- public static void main(String[] args)throws Exception {
- arrayListTest();
- }
-
- private static void readConfig()throws Exception {
- //当我config.properties放在一个包内部的时候,为什么下面这行也可以正常运行
- // src//cn//zxx//basemore//config.properties 为什么这个也行呢 ?
-
- InputStream ips = new FileInputStream("src/cn/zxx/basemore/config.properties");
- Properties props = new Properties();
- props.load(ips);
- ips.close();
-
- String className = props.getProperty("className");
- Collection<ReflectPoint> c = (Collection<ReflectPoint>) Class.forName
- (className).newInstance();
-
- ReflectPoint pt1 = new ReflectPoint(3,3);
- ReflectPoint pt2 = new ReflectPoint(4,4);
- ReflectPoint pt3 = new ReflectPoint(3,3);
-
- c.add(pt1);
- c.add(pt2);
- c.add(pt3);
- c.add(pt1);
-
- System.out.println("readConfig() : "+c.size());
- }
复制代码 |