Original address: http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.28
This is my translation for the time being.
A constant expression is an expression that represents a basic data type or a string data type, and is a value that can be computed during compilation. Consists of the following points:
- The base data type or the literal value of the string data type
- Convert to basic data type or string (this is not very understanding)
- Unary operator: +,-, ~,and,! (but not including ++or--)
- Multiplication Operator: *,/
- Shift operators: <<,>> and >>>
- Relational operator: <,<=,>,>=
- Comparison operator: ==,!=
- Bitwise AND logical operators: &,^.|
- Conditions and conditions or operators: &&,| |
- Ternary operator:? :
- An expression with parentheses, in which the contents of this parenthesis are a constant expression
- A simple variable name that refers to a constant expression, final int x = 0; y = x;//This x is a simple variable name
- The name of the type. Variable name, which refers to a constant expression Math.PI
Constant expressions of type string tend to be unique through the interned () method, so the string type is often interned (this does not know how to describe it)
Personal understanding, if there is an incorrect place, welcome to point out
Java constant expression