Hello All,
Though the below snippet works fine, I have couple of questions to better understand on exactly what is happening behind.
Say I have a code like below
As you have noticed from the above code, parameter "param" is being passed to execute method and in turn that is being used inside run() method of inline anonymous implementation of Runnable.
If we keep inline declaration aside, technically this should have been technically equivalent to
and in ExecutorService
So, if we compare the first and second ExecutorService, are the steps to set the param and making it available with in run() method of and others are happening behind the scenes by compiler. If Yes, how would compiler determine, if that should use a setter or a constructor to make sure the param is available to Runnable instance.
Also, is there any prominence in declaring the param as "final" with respect to this kind of method passing.
Please advise.
Though the below snippet works fine, I have couple of questions to better understand on exactly what is happening behind.
Say I have a code like below
As you have noticed from the above code, parameter "param" is being passed to execute method and in turn that is being used inside run() method of inline anonymous implementation of Runnable.
If we keep inline declaration aside, technically this should have been technically equivalent to
and in ExecutorService
So, if we compare the first and second ExecutorService, are the steps to set the param and making it available with in run() method of and others are happening behind the scenes by compiler. If Yes, how would compiler determine, if that should use a setter or a constructor to make sure the param is available to Runnable instance.
Also, is there any prominence in declaring the param as "final" with respect to this kind of method passing.
Please advise.