I like to know do we synchronize the instance variable which are final. As variables are final there can not be change in the value.
Can anybody explain this?
I like to know do we synchronize the instance variable which are final. As
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.
Yes. You still have to synchronize mutable objects
final != immutable
Later
You’re declaring, that a given attribute can’t be changed during the object life time.
This increases the security ( your object attribute can’t be replaced by a malicious subclass )
Allows compiler optimizations ( because it knows that only a reference will be used ever )
Prevents subclasses from changing it and so on.
An attribute that is both, final and immutable ( like String, Integer and others ) doesn’t need synchronization.