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?
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.