It seems logical to do some optimization around static final constants ( e.g. replace the variable with literals etc ) to improve the performance
It seems logical to do some optimization around static final constants ( e.g. replace
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For inlinable constants (strings, numbers) the compiler does behave differently, yes.
When the compiler spots a constant expression, it embeds the result of that constant expression into the code that uses it, rather than computing it each time. So if you had:
then the constant value 50 would be directly embedded in the code.
Note that this has a versioning caveat associated with it – if you change
FOOorBAR, you need to recompile everything that refers to it as well… otherwise they’ll still be using the “old” value as it will be embedded in their bytecode.