I have code like this within a method:
final TouchableSpan touchableSpan = new TouchableSpan() {
@Override
public void onClick(View widget) {
this.setPressed(true);
String extravar = touchableSpan.getMyVar();
}
On this line String extravar = touchableSpan.getMyVar();
I get a warning that variable touchableSpan
might have not been initialized. Why is there?
This warning appeared when I added final
modifier. Before I had variable is access from inner class, needs to be declared final
.
You first create an anonymous class and then assign it to the final variable. Thus your onClick
method theoretically might be called before final variable initialization. Why not just using this.getMyVar()
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With