StringBuffer is obsolete?

后端 未结 5 1493
梦毁少年i
梦毁少年i 2021-02-03 17:16

In the book \"Effective Java\", Josh Bloch says that

StringBuffer is largely obsolete and should be replaced by the non-synchronized implementation \'S

5条回答
  •  孤独总比滥情好
    2021-02-03 18:08

    Why is the StringBuffer class now obsolete?

    Because its operations are synchronized, which adds overhead and is rarely useful.

    The reason why you still see StringBuffer used widely is simply inertia: There are still countless code examples tutorials out there that were never updated to use StringBuilder, and people still learn outdated practices (not just this one) from such sources. And even people who know better often fall back to old habits.

提交回复
热议问题