我正在阅读关于GWT的 UIBinder 的文档,第一个代码片段让我感到困惑:
public class HelloWorld extends UIObject {//可以扩展Widget而不是接口MyUiBinder扩展了UiBinder< DivElement,HelloWorld> {} private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class); @UiField SpanElement nameSpan; public HelloWorld(){ // createAndBindUi初始化this.nameSpan setElement(uiBinder.createAndBindUi(this)); $ b在第二行上创建一个本地接口, UiBinder 界面。但是,在第三行中,使用 GWT.create()创建此接口的实例。
这怎么可能?没有一个类实现 MyUiBinder ,所以它不能被实例化,对吗?
解决方案GWT.create 在编译时由GWT Java编译器专门处理。 GWT 类是Google将低级魔术加入到GWT中的地方。
在这个问题下的更多细节。
I'm reading the docs on the UIBinder of GWT and the first code snippet made me confused:
public class HelloWorld extends UIObject { // Could extend Widget instead interface MyUiBinder extends UiBinder<DivElement, HelloWorld> {} private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class); @UiField SpanElement nameSpan; public HelloWorld() { // createAndBindUi initializes this.nameSpan setElement(uiBinder.createAndBindUi(this)); } }On the second line an interface is created locally which extends the UiBinder interface. However, on the third line an instance of this interface is created using GWT.create().
How is this possible? There's nowhere a class that implements MyUiBinder, so it can't be instantiated, right?
解决方案GWT.create is treated specially by the GWT Java compiler at compile time. The GWT class is the place where Google puts the low-level "magic" that makes GWT work.
More details under this question.
更多推荐
在JAVA中实例化接口?
发布评论