我正在阅读GWT
的代码
基本上,在这个项目中,他们从属性文件
中获取一些常量
值,例如按钮文本。
所以他们有一个接口(interface)LocalizedResource
并获取类似的实例
public interface LocalizableResource extends Constants {
public static class Util {
public static LocalizableResource getInstance() {
return GWT.create(LocalizableResource.class);
}
}
String lblName_text_1();
}
并使用
此实例
来获取按钮文本
String buttonText = LocalizableResource.Util.getInstance().lblName_text_1();
Button b = new Button(buttonText);
在java中我们不能实例化接口(interface)
,
GWT 是如何做到这一点的。我对延迟绑定(bind)和 GWT 没有太多想法。
最佳答案
这就是 GWT 的美妙之处,也是它管理多个客户端的方式之一,这是 GWT 框架的核心优势。
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsDeferred.html
Deferred binding is a feature of the GWT compiler that works by generating many versions of code at compile time, only one of which needs to be loaded by a particular client during bootstrapping at runtime. Each version is generated on a per browser basis, along with any other axis that your application defines or uses. For example, if you were to internationalize your application using GWT’s Internationalization module, the GWT compiler would generate various versions of your application per browser environment, such as “Firefox in English”, “Firefox in French”, “Internet Explorer in English”, etc… As a result, the deployed JavaScript code is compact and quicker to download than hand coded JavaScript, containing only the code and resources it needs for a particular browser environment.
关于java - 通过 GWT 中的延迟绑定(bind)实例化接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36419273/