Per the Java Language Spec (sect 3.10.5), at http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html.  Bold is mine:

- 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 at run time are newly created and therefore distinct.
- The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents. 

On Oct 28, 2008, at 3:16 PM, Randall Hauch wrote:

I don't believe you're right, at least for string literals available at compile-time.  Those are all interned into the same bucket.

On Oct 28, 2008, at 2:38 PM, John Verhaeg wrote:

I believe your comments below are not entirely accurate.  There is both a performance and footprint benefit to having such a constant, albeit small in either case.  Java ensures a single entry for an empty string exists in a class's literal pool within the bytecode, but I don't know of any other internalization or special handling for this.  Each class that uses the empty string would have its own bytecode to represent the literal empty string.  The constant avoids both this and the instantiation of said string whenever the class itself is instantiated.

I'd also argue that the EMPTY_STRING constant is more readable, although longer to type, than "".  :-P

John Verhaeg
Red Hat, Inc.
(314) 336-2950

----- dna-commits@lists.jboss.org wrote: 
| Author: rhauch
| Date: 2008-10-28 15:21:10 -0400 (Tue, 28 Oct 2008)
| New Revision: 594
| 
| Modified:
|    trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java
|    trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java
| Log:
| Removed the static constant for an empty string, as Java always interns all string literals such as "".  So, there is no performance or efficiency benefit, and its simpler (if not shorter) to use "" rather than a constant.
| 
| 
| Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java
| ===================================================================
| --- trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java        2008-10-28 17:55:47 UTC (rev 593)
| +++ trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java        2008-10-28 19:21:10 UTC (rev 594)
| @@ -32,7 +32,6 @@
|  import org.jboss.dna.common.collection.ThreadSafeProblems;
|  import org.jboss.dna.common.i18n.I18n;
|  import org.jboss.dna.common.util.CheckArg;
| -import org.jboss.dna.common.util.StringUtil;
|  
|  /**
|   * A basic progress monitor.
| @@ -64,8 +63,8 @@
|  
|      public SimpleProgressMonitor( String activityName,
|                                    ProgressMonitor parentProgressMonitor ) {
| -        this.activityName = activityName == null ? StringUtil.EMPTY_STRING : activityName.trim();
| -        this.parentActivityName = parentProgressMonitor == null ? StringUtil.EMPTY_STRING : parentProgressMonitor.getActivityName();
| +        this.activityName = activityName == null ? "" : activityName.trim();
| +        this.parentActivityName = parentProgressMonitor == null ? "" : parentProgressMonitor.getActivityName();
|          this.taskName = null;
|          this.taskNameParams = null;
|      }
| 
| Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java
| ===================================================================
| --- trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java        2008-10-28 17:55:47 UTC (rev 593)
| +++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java        2008-10-28 19:21:10 UTC (rev 594)
| @@ -45,7 +45,6 @@
|   */
|  public class StringUtil {
|  
| -    public static final String EMPTY_STRING = "";
|      public static final String[] EMPTY_STRING_ARRAY = new String[0];
|      private static final Pattern NORMALIZE_PATTERN = Pattern.compile("\\s+");
|      private static final Pattern PARAMETER_COUNT_PATTERN = Pattern.compile("\\{(\\d+)\\}");
| 
| _______________________________________________
| dna-commits mailing list
| dna-commits@lists.jboss.org
| https://lists.jboss.org/mailman/listinfo/dna-commits
|
_______________________________________________
dna-commits mailing list
dna-commits@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/dna-commits

_______________________________________________
dna-commits mailing list
dna-commits@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/dna-commits