Talking about String (1)

package test;

public class TestDemo {
	private static String getA() {return "a";}
	
	public static void test() {
		String a = "a";//Although a is a local variable and also points to a constant, its reference is not "enforced" and cannot be changed, so the compiler will consider this variable to be variable
		final String c = "a";//final constrains the immutability of c.
		
		//The result of the three variables is "ab"
		String b = a + "b";
		String d = c + "b";
		String e = getA() + "b";//The compiler will not see what the method returns
		
		String compare = "ab";
		System.out.println(b == compare);
		System.out.println(d == compare);
		System.out.println(e == compare);
	}

	public static void main(String[] args) {
		test();

	}

}
/*
 * result: false
 *      true
 *      false
 *      */

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326262635&siteId=291194637