From: David H. <dav...@gm...> - 2008-03-31 21:06:59
|
On Mon, Mar 31, 2008 at 3:33 PM, mgreenberg <pub...@gm...> wrote: > According to various javadoc and code usage, various methods require the > use of interned strings. I grepped the 2.2.1 release > code base and see various lines like > > if (name == "__class__") > > But don't see anywhere obvious that "__class__" gets interned (but > presumably it does -- is that implicit in classes in a single jar or > something?). String literals in Java source code get interned. >From http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.5: "# Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1). # Literal strings within different classes in the same package represent references to the same String object. # Literal strings within different classes in different packages likewise represent references to the same String object. # Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals. # Strings computed by concatenation at run time are newly created and therefore distinct. " - David |