【问题标题】:Avoid IntelliJ evaluating lazy list避免 IntelliJ 评估惰性列表
【发布时间】:2018-11-20 20:15:47
【问题描述】:

我已经实现了 java.util.List<T> 的实现,它懒惰地计算其元素。

它工作正常,除了当我使用 IntelliJ 调试代码时,它会开始评估整个列表。 IntelliJ 调试器设置为仅显示列表的前 100 个元素,但调试器无论如何都会评估整个列表。

我可以更改 IntelliJ 设置、放置注释、从不同的类派生或更改此行为吗?

这是一个演示问题的更简单的类:

public class LazyList extends AbstractList<Integer> {
    @Override
    public Integer get(int index) {
        // If I place a breakpoint on the next line, IntelliJ starts evaluating 
        // the entire list.
        if (index > 10000) {
            System.out.println("Calling slow method");
            return 1;
        }
        return 0;
    }

    @Override
    public int size() {
        return 100000;
    }

    public static void main(String[] args) {
        LazyList list = new LazyList();
        System.out.println(list.get(100));
    }
}

【问题讨论】:

    标签: java debugging intellij-idea


    【解决方案1】:

    您可以取消选中文件 -> 设置 -> 构建、执行、部署 -> 调试器 -> 在变量视图中启用自动表达式中的复选框。

    【讨论】:

    • 抱歉,不,这不起作用。即使删除了该复选标记,IntelliJ 仍会评估整个列表。看起来它正在调用toArray()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 2014-06-13
    • 2013-03-11
    • 2017-01-18
    • 2018-11-11
    • 2015-05-29
    相关资源
    最近更新 更多