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
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