Java – why do the StringBuffer and StringBuilder append methods discard the value returned by the super call

This is a question of curiosity

public StringBuilder append(String str) {
    super.append(str);
    return this;
}

AbstractStringBuilder. Append (STR) also returns this value Discard the return value (in StringBuilder. Append (..) And return it again, rather than casting the return value of the super call to the current implementation

Solution

My first thought is that casting may be expensive, so it's best if you can avoid it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>