Why are method parameters reassigned to local variables?

后端 未结 2 652
鱼传尺愫
鱼传尺愫 2020-12-10 12:36

While looking through the Java API source code I often see method parameters reassigned to local variables. Why is this ever done?

void foo(Object bar) {
  O         


        
2条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 13:13

    I'd have to look at some real examples, but the only reason I can think to do this is if the original value needs to be preserved for some computation at the end of the method. In this case, declaring one of the "variables" final would make this clear.

提交回复
热议问题