ukyu

IDEA debug ConcurrentLinkedQueue时抽风

1. 介绍

如标题所见,我在使用IDEA debug ConcurrentLinkedQueueOffer方法时,发生了下面的情况。

代码如下:

        ConcurrentLinkedQueue<string> queue = new ConcurrentLinkedQueue<>();
        queue.offer("A");
        queue.offer("B");

第一种打断点的地方:

未取消前,一个断点debug

第二种打断点的地方:

未取消前,两个断点debug

如你所见,相同的地方,打断点的地方不同,导致代码执行的路径都不同,当时我也是迷茫的。

2. 解释原因

IDEA debug 默认设置
IDEA 默认会开启以上两个配置

  • Enable alternative view for Collection classes; Select this option to display contents of classes that implement Collection, Map, or List in a more convenient format (for example, to display each map entry as a key-value pair).属于集合的类以更加方便的格式展示其内容(例如,展示map的entry就以键值对展示)
  • Enable toString() object view;Allows you to configure which classes use the result of toString() as their display value.展示值以它们toString()的结果展示。

debug时,代码之外,额外执行的只有toString,第一个配置也会调用toString,所以我们定位到了罪魁祸首是toString。我们看看ConcurrentLinkedQueuetoString

2.1 toString

我们去看看哪个类中实现了toString
ConcurrentLinkedQueue继承关系

分类:

技术点:

工具

相关文章: