11 Replies Latest reply: Jun 18, 2007 12:36 PM by Puce RSS

    StringBuilder API question

    Puce
      Hi,

      probably I'm just working too long and I have a black-out, but how can StringBuilder implement Appendable ("All Implemented Interfaces" section) with the following class hierarchy:

      public final class StringBuilder
      extends Object
      implements Serializable, CharSequence

      ???

      http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuilder.html

      -Puce
        • 1. Re: StringBuilder API question
          807605
          I don't understand your use of "how can" -- it does, doesn't it? Or are you trying to express some sort of moral outrage? ;-)
          • 2. Re: StringBuilder API question
            807605
            It seems the API isn't completely accurate. From the source:
            public final class StringBuilder
                extends AbstractStringBuilder
                implements java.io.Serializable, CharSequence
            {
            abstract class AbstractStringBuilder implements Appendable, CharSequence {
            • 3. Re: StringBuilder API question
              Puce
              Well, a good way to improve programming skills is by looking to other "good" APIs. Unfortunatly I don't understand this... :-/
              • 4. Re: StringBuilder API question
                Puce
                So the question is, why does the Javadoc say StringBuilder implements Object, when it implements AbstractStringBuilder?
                • 5. Re: StringBuilder API question
                  807605
                  > It seems the API isn't completely accurate.

                  Not that the API is infallible, but what makes you say it's not accurate? StringBuilder provides a concrete implementation for the methods in Appendable, which it inherits from AbstractStringBuilder. How does StringBuilder not implement Appendable?

                  ~
                  • 6. Re: StringBuilder API question
                    807605
                    > It seems the API isn't completely accurate.

                    Not that the API is infallible, but what makes you
                    say it's not accurate? StringBuilder provides a
                    concrete implementation for the methods in
                    Appendable, which it inherits from
                    AbstractStringBuilder. How does StringBuilder
                    not implement Appendable?

                    ~
                    I was referring to the fact that they left out AbstractStringBuilder from the inheritance tree actually :)
                    java.lang.Object
                      extended by java.lang.StringBuilder
                    public final class StringBuilder
                    extends Object
                    implements Serializable, CharSequence
                    • 7. Re: StringBuilder API question
                      807605
                      > So the question is, why does the Javadoc say
                      StringBuilder implements Object, when it implements
                      AbstractStringBuilder?

                      Ah. Now I see what you're asking. AbstractStringBuilder is package-private; it's not part of the public interface. Classes and interfaces with less than protected access are typically excluded from generated javadocs.

                      ~
                      • 8. Re: StringBuilder API question
                        807605
                        Cheeky. Both StringBuffer and StringBuilder extend AbstractStringBuilder.
                        • 9. Re: StringBuilder API question
                          Puce
                          > So the question is, why does the Javadoc say
                          StringBuilder implements Object, when it
                          implements
                          AbstractStringBuilder?

                          Ah. Now I see what you're asking.
                          AbstractStringBuilder is package-private; it's not
                          part of the public interface. Classes and interfaces
                          with less than protected access are typically
                          excluded from generated javadocs.

                          ~
                          Ah, ok, thanks for the clarification! :-)

                          -Puce
                          • 10. Re: StringBuilder API question
                            807605
                            If you want to see everything in the source documented you could generate your own version of the api from your copy of the source.

                            http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html#javadocoptions
                            • 11. Re: StringBuilder API question
                              Puce
                              Ok, thanks! :-)