In Java, static
denotes class methods and class variables (as opposed to instance methods and instance variables). These methods and variables can be accessed without an instance present.
Contrast this to instance methods and instance variables: they must be accessed through an object. For example, length()
operates on an object:
String a = "hello";
int len = a.length();
In contrast, valueOf
cannot operate on an object; moreover, it creates a new object when called:
String x = String.valueOf(123.45);
Note how instance methods are called using <objectName>
followed by a dot .
, while static methods are accessed using <className>
followed by a dot .
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…