Java Reference
In-Depth Information
• The additive operators + and - 15.18 )
• The shift operators << , >> , and >>> 15.19 )
• The relational operators < , <= , > , and >= (but not instanceof ) (§ 15.20 )
• The equality operators == and != 15.21 )
• The bitwise and logical operators & , ^ , and | 15.22 )
• The conditional-and operator && and the conditional-or operator || 15.23 ,
§ 15.24 )
• The ternary conditional operator ? : 15.25 )
• Parenthesized expressions (§ 15.8.5 ) whose contained expression is a constant ex-
pression.
• Simple names (§ 6.5.6.1 ) that refer to constant variables (§ 4.12.4 ).
• Qualified names (§ 6.5.6.2 ) of the form TypeName . Identifier that refer to constant
variables (§ 4.12.4 ) .
Compile-time constant expressions of type String are always “interned” so as to share
unique instances, using the method String.intern .
A compile-time constant expression is always treated as FP-strict (§ 15.4 ), even if it occurs
in a context where a non-constant expression would not be considered to be FP-strict.
Compile-time constant expressions are used in case labels in switch statements (§ 14.11 )
and have a special significance for assignment conversion (§ 5.2 ) and initialization of
a class or interface (§ 12.4.2 ). They may also govern the ability of a while , do , or for
statement to complete normally (§ 14.21 ), and the type of a conditional operator ? :
with numeric operands.
Example 15.28-1. Constant Expressions
Click here to view code image
true
(short)(1*2*3*4*5*6)
Integer.MAX_VALUE / 2
2.0 * Math.PI
"The integer " + Long.MAX_VALUE + " is mighty big."
Search WWH ::




Custom Search