Is there any benefit to returning the result of assigning a value to a local variable rather than the value directly?

前端 未结 6 1118
死守一世寂寞
死守一世寂寞 2021-01-17 09:01

I am doing a java code inspection. Here is a function (snippet):

String getValue() {
     String res;
     StringBuilder strBuilder = new StringBuilder();

         


        
6条回答
  •  情深已故
    2021-01-17 09:42

    Can also be written as:

    String getValue() {
        return new StringBuilder().toString();
    }
    

提交回复
热议问题