A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© wangkai 中级黑马   /  2015-5-31 19:18  /  389 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package com.itheima.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 {

public static void main(String[] args) throws Exception{
  // TODO Auto-generated method stub
  /*getRealPath();//金山词霸/内部
  //一定要记住用完整的路径,但完整的路径不是硬编码,而是运算出来的。*/
  //InputStream ips = new FileInputStream("config.properties");
  
  //InputStream ips = ReflectTest2.class.getClassLoader().getResourceAsStream("com/itheima/day1/config.properties");
  //InputStream ips = ReflectTest2.class.getResourceAsStream("resources/config.properties");
  InputStream ips = ReflectTest2.class.getResourceAsStream("/com/itheima/day1/resources/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 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;
  //collections.remove(pt1);
  
  System.out.println(collections.size());

}

}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马