static methods and static variables are often used in automated tests. So what are static methods and static variables? and under what circumstances? Here's a Talk.
Static and static variables use public memory space, meaning that all objects can be referenced directly, without the need to create objects and then use the method, which is used to modify the traffic with Static.
They all belong to the class itself and are loaded into memory when the class is loaded, not automatically destroyed, and will persist in memory until the JVM shuts down.
Static variables:
public class Assertion { privatestaticnew Log (assertion. Class); public Static Boolean true ; public Static New Arraylist<error> ();
Static method:
public Static boolean Setflag (boolean fla) { flag=fla; return flag; }
Because static members do not need new to be used, efficiency is more efficient than non-static methods, so the following scenarios are more appropriate:
1. assertion, fileutil, log, etc. in frequently used tool classes that do not require the generation of Objects.
2. Object-independent methods can be set to static METHODS.
3. Some common methods in common Classes.
4. Many classes require variables that are set to static and used as global variables.
Static methods of java, static variables