A quickie just to get peace of mind:
Considering the following
final String str = "This is the end";
Is str.length() evaluated at runtime or is it hardcoded as 15 in the bytecode?
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.
str.length()is evaluated at runtime.finalmeans that value of the reference cannot be changed. It has nothing to do with the string itself.However, if you look into the source code of
Stringyou will see thatlength()returns the value of a field, so no computation takes place, the value os simply read…