When to use static method in a java class

First , please understand its feature :

* no need to instantiate a instance, i.e. simply you can just write: AutoTrace.start();

* All instances will share one static method, consider the consistency when the method operate a static (global) variable. [ as to its local variables, each thread has self stack. This's similar to non-static method ] 


Then to consider whether to declare as static :

* If you really no need to construct a java instance before call its method

* the static variable of the static method is immutable or not / no need to consider its consistency [ i.e. locking ]

....

 

posted @ 2013-08-06 19:01  jlins  阅读(186)  评论(0)    收藏  举报