Why is “” marked for Java in sonarqube
•
Java
In Java, I can convert int to string by "" intvalue
Why is this inappropriate As far as I know, integer ToString (intvalue) is more detailed and the same
I can imagine marking it if it is not '', but the object x is used as X intvalue, where x is initialized as an integer Use JavaScript code for similar operations
Solution
As to why it's so bad, Java automatically optimizes string connections to use StringBuilder This means by doing so
"" + d
Are you really doing it
new StringBuilder().append(d).toString();
If you do
d + ""
You finally compiled
new StringBuilder(String.valueOf(d)).toString();
Compared with just making a phone call, this is a considerable waste of resources
String.valueOf(d);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码