java - 通过 GWT 中的延迟绑定(bind)实例化接口(interface)?

标签 java gwt

我正在阅读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/

相关文章:

java - JSF : How to update one session bean base on another session bean?

java - 使用 Spring boot 的 SOAP 和 Rest Web 服务

java - 从源代码中打开类文件

java - 需要此流程的帮助(AudioInputStream -> byte Array -> AudioOutputStream)

gwt - GWT 中的多个入口点

css - 在 GWT 中拆分图像会导致不需要的空白

java - 将自定义检测器与 FindBugs Maven 插件结合使用

java - 我可以在没有入口点的情况下强制进行 GWT 编译吗? (验证与 GWT 的兼容性)

gwt-dispatch - GWT 的命令模式替代方案

java - "Main type not specified"与 GWT 和 Eclipse Juno 4.2