本帖最后由 mohuancaizi 于 2014-3-2 16:28 编辑
- package cn.itcast.day1;
- import java.io.*;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.util.Collection;
- import java.util.Properties;
- import java.util.*;
- public class RefectTest2 {
- /**
- * @param args
- */
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args)throws Exception {
- // TODO Auto-generated method stub
-
- InputStream ips = new FileInputStream("config.properties");//创建一个文件 命名为:config.properties
- Properties props = new Properties();
- props.load(ips);
- ips.close();
- String className = props.getProperty("className");
- Collection collections = (Collection)Class.forName(className).newInstance();//
-
-
- //Collection collections = new ArrayList();//打印结果为4
- //Collection collections = new HashSet();//打印结果为3
- 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;//已经改 哈希值已换
- //collections.remove(pt1);//pt1中原来的哈希值已换 所以删除不了
- System.out.println(collections.size());
- }
- }
复制代码
谁能说说这句话里面代表的意思呢 Collection collections = (Collection)Class.forName(className).newInstance(); ???????????????? |