0

I found that the constant literal is computed at compile time for example:int a=10+20; but when i try to use int b=10/0; i find that it is computed at run time. Can you please tell me why this constant literal is computed at run time? Thank you.

Chimera
  • 5,884
  • 7
  • 49
  • 81
Tushar Paliwal
  • 301
  • 4
  • 11

1 Answers1

3

A constant value MAY be computed at compile time, if the compiler can maintain the same semantics as if it were done at run time. If not (eg, the case of divide by zero) then it defers the computation to run time. For more info read JLS 15.28.

Roger Lindsjö
  • 11,330
  • 1
  • 42
  • 53
Hot Licks
  • 47,103
  • 17
  • 93
  • 151