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

前端 未结 6 1122
死守一世寂寞
死守一世寂寞 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:53

    You're absolutely right; assignment to res makes no sense; return bs.toString(); would do the the same.


    P.S. +1 for not ignoring compiler warnings.

提交回复
热议问题