https://stackoverflow.com/a/180191
Here a method is timed by calling System.nanoTime() in a normal block, while the end time is called for in a finally block?
Was this only done to report a correct time even if the method throws an exception? or does guarantee even more: not only that it will be called but also right after the method (i.e. preventing task switching or similar…) ?
what is the motivation of using final modifiers here?
The only reason to do this is to make sure that the second
nanoTime()is called even in the presence of exceptions.There are no guarantees related to task switching.
As to the
finalmodifiers, I think they are just a matter of personal style, and have no effect on the timings. Like the person who wrote that answer, I often mark variables that are effectively constant asfinal.