For Instance how can I use the input ‘hasTypedSomeToken’ in my Anonymou inner class in the following –
public class Login {
void display(boolean hasTypedSomeToken)
{
//some code here
Button btnLogIn = new Button("Login", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if(Login.this.hasTypedSomeToken) //HOW TO USE hasTypedSomeToken HERE
{
//do something
}
}
}
}
The variables declared within a method are local variables. e.g.
hasTypedSomeTokenandbtnLogInare local variables in yourdisplaymethod.And if you want to use those variables inside a local inner class (classes that are defined inside a method e.g. the anonymous class that implements
ClickHandlerin your case) then you have to declare themfinal.e.g.
If you look at
Login.this.hasTypedSomeToken,thisis used to access member variables. Local variables are not members of class. They are automatic variables that live only within the method.