StringBuffer is obsolete?

后端 未结 5 1492
梦毁少年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:02

    Not everyone reads as widely as you :-)

    I'm only half-joking. People copy code and patterns all the time. Many people don't stay in touch with API changes.

    Why is StringBuffer obsolete? Because in the vast majority of cases, its synchronised behaviour isn't required. I can't think of a time I've ever needed it. Despite the fact that synchronisation is not now the performance issue it once was, it makes little sense to pay that tax in scenarios where it's unnecessary.

提交回复
热议问题