本帖最后由 罗海云 于 2013-2-25 20:57 编辑
- package com.itheima.day01;
- 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
- //一定要记住用完整的路径, 但完整的路径不是硬编码, 而是运算出来的.
- //InputStream ips = new FileInputStream("config.properties");
- InputStream ips = ReflectTest2.class.getClassLoader().getResourceAsStream("com/itheima/day01/config.properties");<FONT color=red>//我就是想问下,为什么getResourceAsStream取路径为什么只用一个/就可以了我看以前基础视频的取路径都是//表示的...</FONT>
- Properties props = new Properties();
- props.load(ips);
- ips.close();
- String className = props.getProperty("className");
- Collection collections = (Collection)Class.forName(className).newInstance();
- //Collection collections = new HashSet();
- ReflectPoint pt1 = new ReflectPoint(3,3);
- ReflectPoint pt2 = new ReflectPoint(5,5);
- ReflectPoint pt3 = new ReflectPoint(3,3);
- collections.add(pt1);
- collections.add(pt2);
- collections.add(pt3);
- collections.add(pt1);
- //pt1.y = 7; <FONT color=#ff0000>//还有为什么假如我把这行注释去掉..然后下面就删不掉了呢?注释结果就是1,不注释结果就是2.
- </FONT>collections.remove(pt1);
- System.out.println(collections.size());
- }
- }
复制代码 麻烦大神们来说下你的理解..和原理
|