The parameter 'foo' should not be assigned — what's the harm?

前端 未结 5 428
感动是毒
感动是毒 2020-12-17 08:52

Compare this method:

void doStuff(String val) {
    if (val == null) {
        val = DEFAULT_VALUE;
    }

    // lots of complex processing on val
}
         


        
5条回答
  •  無奈伤痛
    2020-12-17 09:30

    I suspect it's a style issue; more of a guideline for programmers than an actual potential problem. Some might find it misleading to dispose of the original parameter value.

提交回复
热议问题