Object
:public final class StringBuilder
extends Object
implements Serializable, CharSequence
Is
public final class StringBuffer
extends Object
implements Serializable, CharSequence
Object
really the direct superclass of StringBuilder
and StringBuffer
? Since the two string-related classes are so similar (see my previous post for a short comparison), doesn't it make sense for them to have a common superclass?Yes, they do share a common abstract superclass,
java.lang.AbstractStringBuilder
, as revealed in their source code:public final class StringBuilder
extends AbstractStringBuilder
implements java.io.Serializable, CharSequence {
/** use serialVersionUID for interoperability */
static final long serialVersionUID = 4383685877147921099L;
...
AbstractStringBuilder
is an abstract class with package access type:abstract class AbstractStringBuilder
implements Appendable, CharSequence {
Tags: