public class ThreadString extends Thread {
String str = "ABC";
public void run() {
str = "abc";
}
}
if threads are accessing above run method, reference to the "ABC" now pointing to "abc" how it will works internally?
String
s in Java are immutable. You aren't modifying the String
, you're just pointing to another value. From that point of view, it's thread safe - str
is either "ABC"
or "abc"
, it can't be something invalid or illegal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With