static is to make it a member of a class, not an object, so it is convenient to use
public is for easy access
final means that this is a constant and cannot be modified
Private objects, and then define get and set for access control, which is a conventional encapsulation
To sum up, public static final can make access very convenient and will not be modified. Generally, configuration information can be placed, as well as some status code definitions.
Other additions:
The static modified object is placed under the root of the reference, which means it will almost never be recycled
static is static. Variables modified by static can be called directly using the class name and variable name without the need to refer to the instantiated object of the class. final modified variables are mostly used to declare a constant when the variable is first used. After the first assignment, this variable is equivalent to a constant or can be understood as the value of this variable is fixed and the value cannot be modified
public class Constant {
public static final int DEAFULT_TAG = 0xcc33;
public static final int DEFAULT_VERSION = 1;
public static final Long PHOTO_PRICE = 1L;
public static final String OSS_STYLE = "?x-oss-process=style/photo_printer";
}
The above Constantas a constant class, when I need to call constants in various other places
Answer the question first
static is to make it a member of a class, not an object, so it is convenient to use
public is for easy access
final means that this is a constant and cannot be modified
Private objects, and then define get and set for access control, which is a conventional encapsulation
To sum up,
public static final
can make access very convenient and will not be modified. Generally, configuration information can be placed, as well as some status code definitions.Other additions:
The static modified object is placed under the root of the reference, which means it will almost never be recycled
static is static. Variables modified by static can be called directly using the class name and variable name without the need to refer to the instantiated object of the class.
final modified variables are mostly used to declare a constant when the variable is first used. After the first assignment, this variable is equivalent to a constant or can be understood as the value of this variable is fixed and the value cannot be modified
Global constants. For example, the global configuration of the project can be modified with public static final
Private is defined and cannot be accessed from other classes. So what's the point of such a constant definition?
Static constants, give me an example
The above
Constant
as a constant class, when I need to call constants in various other placesJust use
Constant.OSS_STYLE
directlyTo put it bluntly, it is to facilitate access and increase code readability. There is not much difference in performance.