8/28/2006

What is the Superclass of StringBuilder and StringBuffer

Their javadoc page shows they both extend from Object:

public final class StringBuilder
extends Object
implements Serializable, CharSequence

public final class StringBuffer
extends Object
implements Serializable, CharSequence
Is 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 {

3 comments:

Anna said...

Great and Useful Article.

Online Java Training

Java Online Training India

Java Online Course

Java EE course

Java EE training

Best Recommended books for Spring framework

Java Interview Questions








Java Course in Chennai

Java Online Training India

eMexo Technologies said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

Internet Of Things training in electronic city

Cipro said...

A website is much powerful than you could ever imagine. Strategic website design by improving user experience can improve your online friv 2020 sell & conversion. It's can make you successful in business. Thanks!