which is better String add; while(XXX) { add=XXXX .... } or while(XXX) { String add=XXXX .... }
g*y
2 楼
I would use second -- it restrict the variable "add" in local, that gives yourself a better protection from making mistakes. Example -> String add; while(XXX) { add = XXXX ... (200 lines) } String message = getMessage(add); This program runs fine. One month later, you accidentally change that "add" in the 200 lines, forgot that message also depends on "add". Now your trouble starts. During a variable's life cycle, you always need to remeber and be responsible for it. Just to make your life
【在 p***p 的大作中提到】 : which is better : String add; : while(XXX) { : add=XXXX : .... : } : or : while(XXX) { : String add=XXXX : ....
p*p
3 楼
why no diff in performance? new instances are repeatly created