1

We often use loggers in our code for debugging purpose. We write something like this

logger.debug("");

My question is, doesn't it create lots of objects since we use String literals in debug statements so much? Is there any alternative to avoid it?

4

1 回答 1

0

字符串字面量在共享池中分配,因此不会浪费空间。每个相等的字符串共享一个实例。

根据String.intern() ,文字是实习的。

于 2013-07-23T05:36:27.233 回答