Going through a tutorial for android (related to multithreading, loopers and handlers), i came across this:
public synchronized void enqueueDownload(final DownloadTask task)
My questions are:
In Java this is usually so that you can access the parameter within an anonymous inner class - which is often used in Android for event handlers and the like.
The real meaning is that the parameter's value cannot be changed within the method, but the purpose is usually for anonymous inner classes...
public synchronized void enqueueDownload(final DownloadTask task) {
SomethingHandler handler = new SomethingHandler() {
@Override public void handleSomething() {
// This would not compile if task were not final
task.doSomething();
}
};
// Use handler
}
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