sealw:
像guice、spring这样的框架,一般是通过反射生成实例,再强制类型转换返回
[阅读: 294] 2009-05-18 23:37:24
<T> T inject(Class<T> implementation, InternalContext context) {
try {
ConstructorInjector<T> constructor = getConstructor(implementation);
return implementation.cast(
constructor.construct(context, implementation));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
http://www.koders.com/java/fid1EADF59AF6175D22EA481EE603B0800C21167EAC.aspx