execute
is a SwingWorker
method. What you see is an anonymous class created and having an execute
method that is called immediately.
I have to admit that I'm a little surprised that the code is compiling because it seems to assign the execute
result to the worker
variable, and the documentation says that execute
is void
.
If we look at this code a bit, it might be clearer. First, we create an anonymous class that extends SwingWorker
, and instantiate it at the same time (this is a big bit in parentheses):
SwingWorker tmp = new SwingWorker<ImageIcon[], Object>() { public ImageIcon[] doInBackground() { final ImageIcon[] innerImgs = new ImageIcon[nimgs]; ...
Then we call execute
and assign the result to worker
(which is a bit which, it seems to me, should not be compiled):
SwingWorker worker = tmp.execute();
Update . And indeed, I tried this, and it does not compile ., So this is not a great example of code. This will compile:
SwingWorker worker = new SwingWorker<ImageIcon[], Object>() { public ImageIcon[] doInBackground() { final ImageIcon[] innerImgs = new ImageIcon[nimgs]; ...
source share