代码之家  ›  专栏  ›  技术社区  ›  Rasmus Faber

避免IntelliJ计算惰性列表

  •  1
  • Rasmus Faber  · 技术社区  · 6 年前

    我已经实现了 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));
        }
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Mureinik    6 年前

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