public static void main(String[] args) throws Exception{
InputStream in = AopFrameWorkTest.class.getResourceAsStream("config.properties");
Object bean = new BeanFactory(in).getBean("XXX");
((ArrayList)bean).clear();
System.out.println(bean);
System.out.print(bean.getClass().getName());
}
}
复制代码
把((ArrayList)bean).clear; 注释掉会得到下面的运行结果:
方法开始---执行前===========================
方法开始---执行后======
toString-------running time :0
class java.util.ArrayList
$Proxy0
不注释的话,运行结果会出现类型转换异常,如下所示:
Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to java.util.ArrayList
at aopframeworktest.AopFrameWorkTest.main(AopFrameWorkTest.java:8)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
config。properties 文件的内容为: