由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - a stupid question
相关主题
问个exception的问题Re: How to creat a newinstance with a param??
An interesting thing about java generics-do not laugh at me if u think it too basic折腾了一天,实在是绝望了,请教请教
土问一个简单问题Re: Java中如何动态生成对象(Yuns的解释)
java问题:如何match两个正规表达式Re: how to write a string to a new file
java string streamRe: how to initialize corba object orb in servlet
出个简单题,看你Java APi熟悉到什么程度java String
how to update swing componentsRe: 怎样递归操作目录,子目录以及他们下面的文件?
byte[] to int[]一个Java程序员的话(3)
相关话题的讨论汇总
话题: add话题: string话题: xxxx话题: xxx话题: stupid
进入Java版参与讨论
1 (共1页)
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
1 (共1页)
进入Java版参与讨论
相关主题
一个Java程序员的话(3)java string stream
Re: 急问关于applet里打开文件的问题出个简单题,看你Java APi熟悉到什么程度
2 Questions about Constructorhow to update swing components
高手请进: gabbage collection problembyte[] to int[]
问个exception的问题Re: How to creat a newinstance with a param??
An interesting thing about java generics-do not laugh at me if u think it too basic折腾了一天,实在是绝望了,请教请教
土问一个简单问题Re: Java中如何动态生成对象(Yuns的解释)
java问题:如何match两个正规表达式Re: how to write a string to a new file
相关话题的讨论汇总
话题: add话题: string话题: xxxx话题: xxx话题: stupid