This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes String literals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "String literals" Watch "String literals" New topic
Author

String literals

Mukul Anand
Greenhorn

Joined: Nov 28, 2012
Posts: 29
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
Sheriff

Joined: Sep 28, 2004
Posts: 18875
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
GeeCON Prague 2014
 
subject: String literals