Bellow is some Java code from Google’s UIBinder tutorial. Together with a separate HTML page this code displays the text “Hello, World”.
public class HelloWorld {
interface MyUiBinder extends UiBinder<DivElement, HelloWorld> {}
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
@UiField SpanElement nameSpan;
public HelloWorld() {
setElement(uiBinder.createAndBindUi(this));
}
public void setName(String name) {
nameSpan.setInnerText(name);
}
/**
* Method in question
*/
public void Element getElement() {
return nameSpan;
}
}
The getElement() method has a void return type but returns an Element called nameSpan. How is this possible given that it has a void return type?
The explanation is simply, that the example in the documentation is “a little bit” broken.
The implementation of
setElement()andgetElement()would be unnecessary anyway, if the example simply extended UIObject likeBy the way, here’s a standalone variation of the UiBinder “hello world” example (which might be easier to understand as a first UiBinder example):