I am defining a callback and would like to reference the callback internally. The compiler does not like this and claims that the variable related to the callback is not initialized. Here is the code:
final Runnable callback = new Runnable() { public void run() { if (someCondition()) { doStuffWith(callback);
Obviously, the compiler is wrong, since by the time the internal method callback has been reached. How do I tell the compiler that this code is fine, or how can I write it differently to calm the compiler? I havenβt done a lot of Java, so I could bark the wrong tree. Is there any other idiomatic way to do this? It seems to me that this is a fairly simple design.
edit: Of course, that was too easy. Thanks for all the quick answers!
source share