/[classpath]/classpath/java/lang/String.java
ViewVC logotype

Diff of /classpath/java/lang/String.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.53 by mkoch, Thu May 22 07:25:26 2003 UTC revision 1.54 by mark, Tue Jul 15 20:39:48 2003 UTC
# Line 41  package java.lang; Line 41  package java.lang;
41    
42  import java.io.Serializable;  import java.io.Serializable;
43  import java.io.UnsupportedEncodingException;  import java.io.UnsupportedEncodingException;
 import java.lang.ref.WeakReference;  
44  import java.util.Comparator;  import java.util.Comparator;
 import java.util.WeakHashMap;  
45  import java.util.Locale;  import java.util.Locale;
46  import java.util.regex.Pattern;  import java.util.regex.Pattern;
47  import java.util.regex.PatternSyntaxException;  import java.util.regex.PatternSyntaxException;
# Line 89  public final class String implements Ser Line 87  public final class String implements Ser
87    private static final long serialVersionUID = -6849794470754667710L;    private static final long serialVersionUID = -6849794470754667710L;
88    
89    /**    /**
    * Holds the references for each intern()'d String. If all references to  
    * the string disappear, and the VM properly supports weak references,  
    * the String will be GC'd.  
    */  
   private static final WeakHashMap internTable = new WeakHashMap();  
   
   /**  
90     * Stores unicode multi-character uppercase expansion table.     * Stores unicode multi-character uppercase expansion table.
91     * @see #toUpperCase(char)     * @see #toUpperCase(char)
92     * @see CharData#UPPER_EXPAND     * @see CharData#UPPER_EXPAND
# Line 1596  public final class String implements Ser Line 1587  public final class String implements Ser
1587    }    }
1588    
1589    /**    /**
1590     * Fetches this String from the intern hashtable. If two Strings are     * If two Strings are considered equal, by the equals() method,
1591     * considered equal, by the equals() method, then intern() will return the     * then intern() will return the same String instance. ie.
1592     * same String instance. ie. if (s1.equals(s2)) then     * if (s1.equals(s2)) then (s1.intern() == s2.intern()).
1593     * (s1.intern() == s2.intern()). All string literals and string-valued     * All string literals and string-valued constant expressions
1594     * constant expressions are already interned.     * are already interned.
1595     *     *
1596     * @return the interned String     * @return the interned String
1597     */     */
1598    public String intern()    public String intern()
1599    {    {
1600      synchronized (internTable)      return VMString.intern(this);
       {  
         WeakReference ref = (WeakReference) internTable.get(this);  
         if (ref != null)  
           {  
             String s = (String) ref.get();  
             // If s is null, then no strong references exist to the String;  
             // the weak hash map will soon delete the key.  
             if (s != null)  
               return s;  
           }  
         internTable.put(this, new WeakReference(this));  
       }  
     return this;  
1601    }    }
1602    
1603    /**    /**

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.54

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26