Compile-time calculation: Difference between revisions
m
Added more explanation about Java's compile time limitations.
(→{{header|Raku}}: rephrasing and removing parenthesis) |
m (Added more explanation about Java's compile time limitations.) |
||
Line 838:
=={{header|Java}}==
The Java compiler is able to calculate expressions that contain constant variables
and certain operators during code compilation.
As defined in the Java language specification,
the following operators and expressions may be used for constant expressions:
Unary operators: +, -, ~, !
Multiplicative operators: *, /, %
Additive operators: +, –
Shift operators: <<, >>, >>>
Relational operators: <, <=, >, >=
Equality operators: ==, !=
Bitwise and logical operators: &, ^, |
Conditional-and and the conditional-or operator: &&, ||
Ternary conditional operator: ?:
Parenthesized expressions whose contained expression is a constant expression
Simple names that refer to constant variables
<syntaxhighlight lang="java">
public final class CompileTimeCalculation {
Line 848 ⟶ 860:
public static void main(String[] aArgs) {
System.out.println(tenFactorial);
}
private static int tenFactorial = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1;
}
Line 861 ⟶ 869:
<pre>
3628800
</pre>
|