Sunday, March 29, 2020

[Java][Resolved] String constructor invocation surriund with...


This is a warming by netbean and the warming message is :
String constructor invocation surround with...

source :
String s = new String("leg");


Since String class in immutable in Java and it's not memory efficient. To correct the warming, please remove the string constructor invocation and useconstructor argument directly.
String s = "leg";

Reference:
https://www.inf.unibz.it/~calvanese/teaching/05-06-ip/lecture-notes/uni02/node25.html
https://help.semmle.com/wiki/display/JAVA/Inefficient+String+constructor

No comments :

Post a Comment