class="java" name="code"> package 测试; public class TestDemo { private static String getA() {return "a";} public static void test() { String a = "a";//a虽然是一个局部变量,也指向一个常量,但其引用上并未"强制约束"是不可改变的,因此编译器会认为这个变量可变 final String c = "a";//final约束了c不可变. //三个变量结果为"ab" String b = a + "b"; String d = c + "b"; String e = getA() + "b";//编译器是不会看方法返回了什么内容 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(); } } /* * 结果:false * true * false * */