wood burning stoves
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


Win a copy of Building Microservices this week in the Design forum!
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: 20057
    
  44

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)
 
Have you checked out Aspose?
 
subject: String literals
 
It's not a secret anymore!