Description
Dm: invokes inefficient new String() constructor
Creating a new java.lang.String object using the no-argument constructor wastes memory because the object so created will be functionally indistinguishable from the empty string constant “”. Java guarantees that identical string constants will be represented by the same String object. Therefore, you should just use the empty string constant directly.
使用沒參數的String建構元,造成記憶體浪費。
Solution
用空字串取代new String();
Example
Before:
String emptyStr = new String();
After:
String str = "";
留言
張貼留言