When and why does an EventHandler require objects to be final?

Posted by Michiel Borkent on Stack Overflow See other posts from Stack Overflow or by Michiel Borkent
Published on 2010-05-11T08:37:51Z Indexed on 2010/05/11 8:44 UTC
Read the original article Hit count: 168

Filed under:
|
|
|

I have the following code from a GWT Project that is part of the onModuleLoad() method (similar to Java's main method, if you don't know GWT):

final TextBox t1 = new TextBox();
final Label lt1 = new Label(); 

t1.addKeyUpHandler(new KeyUpHandler() {

    @Override
    public void onKeyUp(KeyUpEvent event) {
        // TODO Auto-generated method stub
        if (!(t1.getText().matches("\\w{2}-\\w{2}-\\w{2}")))
            lt1.setText("Invalid.");
            else
            lt1.setText("OK.");
    }
});

Why do the two local variables have to be final here?

© Stack Overflow or respective owner

Related posts about java

Related posts about final