The good thing about being a nobody is that you are perfect.
That is mistaken, I am afraid. Strings aren't primitives. The name of the method looks misleading, too.Abhishk Singh wrote:. . . str1 and str2 are primitive
I am not certain, but I think you are right for such utility methods. Instances can suffer synchronisation problems, but you won't have any instances of that class.. . . every caller's method stack is separate, there should not be any issue. . . .
Campbell Ritchie wrote:That is mistaken, I am afraid. Strings aren't primitives. The name of the method looks misleading, too.
The good thing about being a nobody is that you are perfect.
Abhishk Singh wrote:It could be an issue if the caller threads were passing object references to same objects.
Today is the first day of the rest of your life.
Today is the first day of the rest of your life.
Mohammed Sardar. wrote:Abhishk, If we don't bother to use append method in return, we we should not try and see with StringBuffer which is fail-safe too ?
Only a suggestion.Please add your thoughts to it if there is any impact.
The good thing about being a nobody is that you are perfect.
I hope nobody would even think of creating such a static field. That would produce all sorts of problems other than loss of thread‑safety.Abhishk Singh wrote:. . . if it becomes a Static variable of the class in which static contatenateStrings method is defined.
Right. Even if its a StringBuffer, because its shared between different threads. If there are 4 statements modifying the stringBuffer object with first statement resetting it inside the method concatenateStrings and one thread loses control after executing 2nd statement and another thread starts at 1st statement and resets the buffer, we lost the modification done by thread one.Campbell Ritchie wrote:Come to thin of it: would a StringBuffer lose its thread‑safety as a static field?
The good thing about being a nobody is that you are perfect.
The good thing about being a nobody is that you are perfect.
Don't get me started about those stupid light bulbs. |