今天给大家带来几个我日常工作以及阅读源码必备的 IntelliJ IDEA 高级调试技巧,分分钟要起飞的节奏。
断点处添加 log
很多程序员在调试代码时都喜欢 print
一些内容,这样看起来更直观,print 完之后又很容易忘记删除掉这些没用的内容,最终将代码提交到 remote
,code review 时又不得不删减这些内容重新提交,不但增加不必要的工作量,还让 log tree
的一些节点没有任何价值
IntelliJ IDEA 提供 Evaluate and Log at Breakpoints
功能恰巧可以帮助我们解决这个问题, 来看下面代码:
public static void main(String[] args) {
ThreadLocalRandom random = ThreadLocalRandom.current();
int count = 0;
for (int i