p***p 发帖数: 559 | 1 which is better
String add;
while(XXX) {
add=XXXX
....
}
or
while(XXX) {
String add=XXXX
....
} | g**********y 发帖数: 14569 | 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 发帖数: 559 | 3 why no diff in performance? new instances are repeatly created |
|