为什么在Java中,当String是一个类时,你能用+运算符添加字符串?在String.java代码中我没有找到该运算符的任何实现.这个概念是否违反了面向对象?
几分钟前我看到了这个问题,并决定查看java String类来检查+运算符是否有一些重载.
我找不到任何东西,但我知道我能做到这一点
String ab = "ab";
String cd = "cd";
String both = ab + cd; //both = "abcd"
Run Code Online (Sandbox Code Playgroud)
实施的地方在哪里?
String s1 = "String";
String s2 = "String" + "";
String s3 = "" + s2;
System.out.println (s1 == s2);
System.out.println (s2 == s3);
System.out.println (s1 == s3);
true
false
false
Run Code Online (Sandbox Code Playgroud)
为什么我会得到错误的价值观?字符串池中不应该是s3变量?一样的.好像我完全不了解String pool.