Redian新闻
>
Suggestion Re: 发现 synchronized 的一个问题
avatar
Suggestion Re: 发现 synchronized 的一个问题# Java - 爪哇娇娃
c*r
1
static variables seem very rare. If you need several instances
to share an object, you can make it as an instance member and pass
it in the constructor. If you really need global variables,
put them in a special class with private constructor.
static finals are fine.
OK, now we have eliminated static variables.
So static methods never have to consider synchronization.
As for parameters, I would suggest parameters be alway read-only.
That is, parameters are inputs to a box (method) and return val
avatar
xt
2

Static methods are *not* rare, especially those utility methods such
as Integer.parseInt( String ). Also static methods and variables play
very important rules in design patterns.

【在 c****r 的大作中提到】
: static variables seem very rare. If you need several instances
: to share an object, you can make it as an instance member and pass
: it in the constructor. If you really need global variables,
: put them in a special class with private constructor.
: static finals are fine.
: OK, now we have eliminated static variables.
: So static methods never have to consider synchronization.
: As for parameters, I would suggest parameters be alway read-only.
: That is, parameters are inputs to a box (method) and return val

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。