java - Do we synchronize instance variables which are final? If yes then whats the use? -
I should know that we synchronize the final frequency variable. Variables are extreme because the price can not be changed. Can anyone explain this?
Do we synchronize such example variables that are the last ones?
Yes you still have to synchronize temp items
Last! = Irreversible
public class Some {Private Final List List = New Array List}; Public zero addition (string value) {this.list.add (value); } Public Entent Count () {return.list.size (); }}
later
some s = new something (); Thread A = New Thread () {Public runs zero () {s.add ("s"); S.add ("s"); S.add ("s"); }}; Thread b = new thread () {public zero run () (sount (); s.count ();}}; start (); b.start ();
If so, what is the use of it?
You are declaring, that a given feature will not be changed during the object lifetime.
Enhances this security (your object attribute can not be replaced by malicious subclasses) Allows compiler optimization (because it goes Only a reference that will be used ever) prevents subclass from changing it and so on.
A feature that synchronizes both the last and the irreversible (eg string, integer and others) Not Required.
Class X {Private Last String Name = "Oscars"; Public Ent NomCount () {return this.name.length ()}; // Always 5> (Actually the compiler can inline it)}
Comments
Post a Comment