Local variables and formal parameters are final.
To open another thread B in a thread A, if thread B wants to use thread A's local variables, then a's local variable needs to be defined as final. Reason: Local variables are shared within threads, and each thread cannot access local variables of other threads, but the appeal is contrary to this principle, so why not add final? The reason is that with final, when the B thread is created, the final tag variable is passed as a parameter of thread B's constructor method to B, which solves this problem, which is a clever approach, which can be seen through the class file anti-compilation.
In addition, Java's string variable is special, and the values of the variables he defines are all stored in the constant pool, whether final or not. The following results are all true. And if the equality points to the same address.
Local variables of the base type also point to the same address if the values are the same. Only the back and the front do not want to wait for the time to point to the new address, which is why the basic local variables do not affect each other for reasons.
public class Stringtest {private static string S1 = "123"; static final string s2 = "123";p ublic static void Main (string[] args) {string s3 = "123"; final String s4 = "123"; System.out.println (S1 = = s2); System.out.println (s3 = = S4); System.out.println (S1 = = S3);}}
Java local variable final