反射,类加载器
来源:互联网 发布:java获取每月第一天 编辑:程序博客网 时间:2024/05/19 12:17
package com.hbsi.reflect;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;
public class ReflectTest2 {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
/**getRealPath();//金山词霸/内部
* 一定要记住用完整的路径,但完整的路径不是硬编码,而是运算出来的
*/
//InputStream ips = new FileInputStream("com/hbsi/reflect/config.properties");
InputStream ips = ReflectTest2.class.getClassLoader().getResourceAsStream("com/hbsi/reflect/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());
}
}
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;
public class ReflectTest2 {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
/**getRealPath();//金山词霸/内部
* 一定要记住用完整的路径,但完整的路径不是硬编码,而是运算出来的
*/
//InputStream ips = new FileInputStream("com/hbsi/reflect/config.properties");
InputStream ips = ReflectTest2.class.getClassLoader().getResourceAsStream("com/hbsi/reflect/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());
}
}
- 反射,类加载器
- 反射+类加载器
- java [反射] [类加载器]
- 反射与类加载器
- java [反射] [类加载器]
- 反射和类加载器
- 反射(1)--类加载器
- java反射---类加载器
- 黑马程序员--反射、内省、类加载器
- 反射,类加载器,动态代理
- 反射_类加载器_代理
- JavaSE--- 类加载器、反射、动态代理
- 类加载器、反射、动态代理
- Java类加载器与反射
- JAVA类加载器和反射
- 13.反射、类加载
- 类加载和反射
- 反射 加载类
- mave的依赖范围
- Drupal 实战
- 常规内网渗透思路总结
- WMS-SearchKey/AlterKey 数组参数注意
- maven常用命令集
- 反射,类加载器
- java.lang.NoClassDefFoundError: junit.framework.TestCase
- MySQL Workbench “Error Code: 1175” 的解决方法 (正确记录)
- 清空Task的Back Stack
- debian下安装nginx
- linux设备树dts移植详解
- 我对进程、线程、异步、同步的理解
- c#桌面应用程序资料收集
- 报错详解