标签:builder margin static 字符串常量 pool print system 总结 地址
为什么String是不可变对象?-----cankai
String s1= "ab" + "cd";
String s2= "abc" + "d";
s1,s2指向的地方是相同的,hashCode值也相同(可以缓存HashCode的值),如果String可以改变,那么s1改变会影响到s2,会带来安全问题。
//Object类的hashCode函数
public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); }
参考文献:
http://www.codeceo.com/article/why-java-string-class-static.html
标签:builder margin static 字符串常量 pool print system 总结 地址
原文地址:http://www.cnblogs.com/yangyunnb/p/6061657.html