suggestBox.addKeyUpHandler( new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
String bo
Because Java doesn't have *real closures* ! ;-)
See this post to know how this is actually implemented.
Because the language designers thought it would be confusing if a variable referenced by an anonymous inner class were changed. If this weren't the case all local variable references referenced by the anonymous class would have to be lifted to be fields of that class.
It's an inner class, passed into addKeyUpHandler
-- all variables referenced outside an inner class need to be declared as final to be used within the inner class. This is because the local class instance must maintain a separate copy of the variable, as it may out-live the function; so as not to have the confusion of two modifiable variables with the same name in the same scope, the variable is forced to be non-modifiable.
Simply do final {type} {new-varname} = {old-varname};
before calling the method that uses the inner class, and then use {new-varname}
inside that.
so that it can't change out from under the anonymous inner class KeyUpHandler implementation.