I\'m trying to understand java byte code. I started with simple example:
public class Test
{
public static void main(String args[])
{
System.
2 + 1 is a compile-time constant expression. The compiler itself replaces it by 3 in the byte-code.
See the Java Language Specification, which says:
Some expressions have a value that can be determined at compile time. These are constant expressions.
See this other chapter for what constitutes a constant expression
A constant expression is an expression denoting a value of primitive type or a String that does not complete abruptly and is composed using only the following:
- Literals of primitive type and literals of type String [...]
- The additive operators + and - [...]