I’m writing for Android (Java).
I’m declaring int’s and float’s as part of an ongoing loop.
Some of them don’t need to be changed after declaration.
If I set them all to final when declaring, will things run quicker?
[Edit]
Thanks everyone. I didn’t actually expect it to make any improvements, I just noticed, after browsing the source of various large projects, it was fairly common. Cheers
Things will not run quicker. The
finalkeyword is just compile time syntactic sugar.If it were actually
static final, then you could take benefit of compiletime calculation and inlining of the value in any refernce. So, with for example:the compiler will optimize one and other so that it ends up like:
If you run a decompiler, you’ll see it yourself.