【问题标题】:Flow of creating instance using GWT.Create and UI-Binder使用 GWT.Create 和 UI-Binder 创建实例的流程
【发布时间】:2019-01-30 09:24:16
【问题描述】:

我正在浏览我们的 GWT 应用程序的代码。并卡在下面的代码中。

private static TestEditorUiBind uiBinder = GWT.create(TestEditorUiBind.class);

interface TestEditorUiBind extends UiBinder<Widget,TestEditorViewImpl> {}

这是我班级的开始 2 行。在此之后,我们使用uiBinder.createAndBindUi(this);创建我们的 GWT 小部件

我知道GWT.create 将在运行时创建TestEditorUiBind 的实例。

但我不明白为什么我们在第二行声明TestEditorUiBind 接口并在GWT.create 的第一行使用它? (我检查了TestEditorUiBind 没有在应用程序的其他任何地方声明)

如果我理解错了,请纠正我。

【问题讨论】:

    标签: java gwt uibinder


    【解决方案1】:

    由于 Java 语言的工作方式,行的顺序无关紧要 - 声明的新类型(枚举、接口、类)中,另一个类型实际上变成了它自己的类型并且不会需要等待在该所有者类型中声明。看起来这两行代码都存在于TestEditorViewImpl.java 中——假设如此,java 编译器实际上会创建两个编译后的字节码文件:

    • TestEditorViewImpl.class
    • TestEditorViewImpl$TestEditorUiBind.class

    然后第一行只询问TestEditorViewImpl$TestEditorUiBind 的实例,它恰好在哪里被声明过。

    所以是的,这个静态字段可能是项目中唯一会使用该类型的地方,因为它特定于将.ui.xml 绑定到此类。可以使用单例,因为此绑定器没有状态,但只会根据在 .ui.xml 文件中找到的内容填充 TestEditorViewImpl 中的字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-21
      • 1970-01-01
      • 2022-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多