Is it problematic to assign a new value to a method parameter?

后端 未结 8 560
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 01:17

Eclipse has an option to warn on assignment to a method\'s parameter (inside the method), as in:

public void doFoo(int a){
   if (a<0){
      a=0; // this         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 01:57

    The confusing-part is the reason for the warning. If you reassign a parameter a new value in the method (probably conditional), then it is not clear, what a is. That's why it is seen as good style, to leave method-params unchanged.

提交回复
热议问题