Skip to main content
added 101 characters in body
Source Link
Gerold Broser
  • 1.3k
  • 8
  • 20

I'd use:

return String.format("%s %s"%f", this.name, this.freshness);

instead of string concatenation:

return this.name + " " + this.freshness + "\n";

for clearness: It shows the structure of the resulting string and the types of the parameters at first glance. 

I'd also omit "\n" since it's up to the caller whether he or she wants a line break. If he or she does notnot want one they are fighting a losing battle with your implementation imposing one.

I'd use:

return String.format("%s %s", this.name, this.freshness);

instead of string concatenation:

return this.name + " " + this.freshness + "\n";

for clearness. I'd also omit "\n" since it's up to the caller whether he or she wants a line break. If he or she does not want one they are fighting a losing battle with your implementation imposing one.

I'd use:

return String.format("%s %f", this.name, this.freshness);

instead of string concatenation:

return this.name + " " + this.freshness + "\n";

for clearness: It shows the structure of the resulting string and the types of the parameters at first glance. 

I'd also omit "\n" since it's up to the caller whether he or she wants a line break. If he or she does not want one they are fighting a losing battle with your implementation imposing one.

Source Link
Gerold Broser
  • 1.3k
  • 8
  • 20

I'd use:

return String.format("%s %s", this.name, this.freshness);

instead of string concatenation:

return this.name + " " + this.freshness + "\n";

for clearness. I'd also omit "\n" since it's up to the caller whether he or she wants a line break. If he or she does not want one they are fighting a losing battle with your implementation imposing one.