考虑到以下2toString()
种实现方式,首选哪种:
public String toString(){
return "{a:"+ a + ", b:" + b + ", c: " + c +"}";
}
或
public String toString(){
StringBuilder sb = new StringBuilder(100);
return sb.append("{a:").append(a)
.append(", b:").append(b)
.append(", c:").append(c)
.append("}")
.toString();
}
?
M或e imp或tantly, given we have only 3 properties it might not make a difference, but at what point would you switch from +
concat to StringBuilder
?