Google Web 工具包 Autobeans

Google Web Toolkit Autobeans

出于好奇,我查看了autobeans是如何生成的。我发现它使用 sun.misc.ProxyGenerator class 生成 autobean proxies 并且它使用 reflections。但我不明白,它是如何在客户端工作的。那些使用reflections的方法编译成javascript了吗?这是否意味着我可以自己在客户端使用反射?

代理实例仅在服务器上使用,在反射起作用的真实 JVM 中。 GWT 代码不能使用一般反射是正确的。

要在客户端生成它们,需要使用 GWT 生成器。这会在 GWT 编译器仍然是 运行 时完成所有反射,在真正的 JVM 中也是如此,并创建新的 classes 来实现您的 autobean 接口和工厂。

com.google.web.bindery.autobean.gwt.rebind.AutoBeanGenerator class 主要负责这项工作,com.google.web.bindery.autobean.gwt.rebind.model 包的内容(在某种程度上,com.google.web.bindery.autobean.shared)协助完成这项工作工作。