- package com.sf.day1;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.HashSet;
- import java.util.Properties;
- public class ReflectTest2 {
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
- //Collection collection=new HashSet();
- InputStream iStream=new FileInputStream("config.properties");
- Properties properties=new Properties();
- properties.load(iStream);
- iStream.close();
- String className=properties.getProperty("className");
- Class cl=Class.forName(className);
- Collection collection=(Collection)cl.newInstance();
- ReflectPoint aPoint=new ReflectPoint(3, 4);
- ReflectPoint bPoint=new ReflectPoint(4, 4);
- ReflectPoint cPoint=new ReflectPoint(5, 4);
- ReflectPoint dPoint=new ReflectPoint(3, 4);
- collection.add(aPoint);
- collection.add(bPoint);
- collection.add(cPoint);
- collection.add(dPoint);
- collection.add(aPoint);
- System.out.println(collection.size());
- }
- }
复制代码- className=java.util.ArrayList
复制代码 看视频好像看完了都明白了,其实一定要自己敲一遍,区别其实很大的,你看我自己敲就出现了好多小问题,比如配置文件config.properties里我自己敲的时候习惯性的敲成了className="java.util.ArrayList;"结果自然是找不到,然后我又回顾了下视频老师怎么写的,然后我改成了className=java.util.ArrayList;发现还是不行,还是找不到,我又对比了下,才发现还多了个分号。所以现在我想问个问题:它这里配置格式是怎么样的?为什么不能加引号,分号。原理是什么呢?谢谢!
|
|