Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5037656

JDK Methods should take parameters of type AbstractStringBuilder, not StringBuff

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp


      Name: gm110360 Date: 04/26/2004


      A DESCRIPTION OF THE REQUEST :
      With the JDK 1.5, class StringBuffer is being split into three classes: AbstractStringBuilder, StringBuffer (a subclass), and StringBuilder (another subclass). Since StringBuilder is more efficient for single-threaded use than StringBuffer, it seems a logical choice for most text processing operations.

      However, this is not well supported by various parts of the standard libraries. For instance, the class java.util.regex.Matcher has a method, 'appendReplacement', which takes as a parameter a StringBuffer into which it will write some text. Another example is SimpleDateFormat.format(...) (and in fact most of the ...Format classes)

      In the JDK 1.5 world, these methods should probably instead take a parameter of type AbstractStringBuilder, so that a user can pass either a StringBuffer or a StringBuilder into the methods, according to the user's synchronization needs.

      In general, I suggest that the JDK should pass values, and hold references to values (inside classes, for instance), of type AbstractStringBuilder rather than StringBuffer as in the past. In general, I think that the only time that the class StringBuffer should be named is right after the 'new' keyword, or where the synchronization abilities of the StringBuffer class are specifically required. Everywhere else should use AbstractStringBuilder.

      JUSTIFICATION :
      Otherwise, users who use StringBuilders will have to create temporary StringBuffers just so that they can call standard library methods that require them, and then write the StringBuffers' contents into a StringBuilder. This would be quite annoying and defeats the whole performance advantage of using StringBuilders in the first place.
      (Incident Review ID: 259822)
      ======================================================================

            Unassigned Unassigned
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: