在JAVA中实例化接口?

编程入门 行业动态 更新时间:2024-10-24 10:26:30
本文介绍了在JAVA中实例化接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在阅读关于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中实例化接口?

本文发布于:2023-08-04 17:38:35,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   接口   JAVA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!