我讀到關於Java的最佳做法的一些建議,我得到了這讓我很好奇最佳實踐好奇心
此外,每當你想實例化一個String對象,從來沒有使用它的構造函數,但總是實例如下想法它直接。
例如:
//slow instantiation
String slow = new String("Yet another string object");
//fast instantiation
String fast = "Yet another string object";
這是爲什麼?不'快速'調用默認的字符串構造函數?
第二種或「快速」方法只創建一個字符串,如果它尚未被實施 – Reimeus 2013-03-26 19:54:49
看看這個:http://stackoverflow.com/questions/2009228/strings-are-objects-in -java那麼爲什麼 - 不要 - 我們使用新到創造,他們 – 2013-03-26 19:55:15