Remove Assignments to Parameters(移除对参数的赋值)
生活随笔
收集整理的這篇文章主要介紹了
Remove Assignments to Parameters(移除对参数的赋值)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
對(duì)入?yún)⑦M(jìn)行賦值
int discount(int inputVal, int quantity, int yearToDate) {if (inputVal > 50) {inputVal -= 2;} }重構(gòu):用一個(gè)臨時(shí)變量取代該參數(shù)
int discount(int inputVal, int quantity, int yearToDate) {int result = inputVal;if (inputVal > 50) {result -= 2;} }什么是“對(duì)參數(shù)賦值”
void method(Object foo) {foo.modifyInSomeWay(); //that's OKfoo = anotherObject; // trouble and despair will follow you. }總結(jié)
以上是生活随笔為你收集整理的Remove Assignments to Parameters(移除对参数的赋值)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 获取字段为List类型中的泛型类型
- 下一篇: 对象设计——责任、角色和协作思维导图笔记