1

In Java API, it declares that the public StringBuilder class extends Object, but in actual fact, OpenJDK declares that it extends a package private AbstractStringBuilder class. Question: why cant Java API just declare that it extends AbstractStringBuilder?

OpenJDK - public final class StringBuffer extends AbstractStringBuilder implements java.io.Serializable, CharSequence

1
  • AbstractStringBuilder is not a public class, so it's just an implementation detail. Commented Apr 26, 2019 at 15:38

1 Answer 1

2

It is a configuration setting used in the javadoc command. You can specify which classes you want to include in the generated javadoc. The default setting is -protected, which will include public and protected classes, but not classes from the package or private ones. Assuming you have the following class hierarchy:

public class TopParentName {} (package) class MiddleName extends TopParentName {} public class LeafName extends MiddleName {} 

When you run the javadoc command without the -package flag you will see only the classes TopParentName and LeafName and you will see that LeafName will extends from TopParentName, even though in the source code it doesn't. But when you use the -package flag, you will see all three classes with the correct inheritance chain.

That being said, the official javadocs are most likely not generated with the -package or -private flag used, therefore the class AbstractStringBuilder class is not visible in the generated javadocs.

Sign up to request clarification or add additional context in comments.

1 Comment

@VirtualInquirer: Please accept this answer if it's helped. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.