The difference between static, final, and static final in Java [transfer]

Description: Not necessarily accurate, but the fastest to understand.

final:

final can be modified: properties, methods, classes, local variables (variables in methods)

The initialization of final-modified properties can be either at compile time or at runtime, and cannot be changed after initialization.

The properties modified by final are related to specific objects. For the final properties initialized at runtime, different objects can have different values.

The final-modified property indicates that it is a constant (it cannot be modified after creation).

A final-modified method means that the method cannot be overridden in subclasses, and a final-modified class means that the class cannot be inherited.

For primitive type data, final turns the value into a constant (which cannot be modified after creation); but for object handles (also called references or pointers), final turns the handle into a constant (when declaring it, you must The handle is initialized to a specific object. And the handle can no longer be pointed to another object. However, the object itself can be modified. This restriction also applies to arrays, which also belong to objects, and the array itself can be modified. Method parameters The final handle in the method means that inside the method, we cannot change the actual thing pointed to by the parameter handle, that is to say, we cannot assign another value to the formal parameter handle inside the method).

static:

static can be modified: properties, methods, code segments, inner classes (static inner classes or nested inner classes)

The initialization of static modified properties is at compile time (when the class is loaded) and can be changed after initialization.

All objects with static modified properties have only one value.

Static-modified properties emphasize that there is only one of them.

Statically modified properties, methods, and code segments have nothing to do with the specific object of the class, and statically modified properties, methods, etc. can be called without creating an object.

Static and "this, super" are incompatible. Static has nothing to do with specific objects, while this and super are related to specific objects.

static cannot modify local variables.

static final和final static:

There is no difference between static final and final static. Generally, static is written in front.

static final:

Static modified properties emphasize that there is only one of them, and final modified properties indicate that it is a constant (can not be modified after creation). A property modified by static final means that once a value is given, it cannot be modified and can be accessed through the class name.

Static final can also modify a method, indicating that the method cannot be overridden and can be called without a new object

 

refer to:

http://blog.csdn.net/qq1623267754/article/details/36190715 (The above content is transferred from this article)

https://www.cnblogs.com/gaopeng527/p/5258206.html

http://blog.163.com/neu_lxb/blog/static/179417010201132332429436/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325294124&siteId=291194637