• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String literals

 
Mukul Anand
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At page no. 63, section 3.10.5,
The Java Language Specification for Java 5/6 states that
Strings computed by constant expressions (§15.28) are computed at compile
time and then treated as if they were literals.

What does the phrase "computed at compile time" mean?
It sounds as if those String objects are created at compile-time, which is funny.
 
Henry Wong
author
Marshal
Pie
Posts: 21427
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mukul Anand wrote:At page no. 63, section 3.10.5,
The Java Language Specification for Java 5/6 states that
Strings computed by constant expressions (§15.28) are computed at compile
time and then treated as if they were literals.

What does the phrase "computed at compile time" mean?
It sounds as if those String objects are created at compile-time, which is funny.


This just means that it is computed by the compiler. For example...



There is no "hello", " ", or "world" strings created by the generated code. The generated code creates the "hello world" string directly -- because the result is computed at compile time. It is as if the code was ...



Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic