【问题标题】:How to add additional methods to autocomplete in IntelliJ如何在 IntelliJ 中添加其他方法来自动完成
【发布时间】:2020-12-14 20:54:04
【问题描述】:

当我使用 IntelliJ 进行编码时,我经常使用自动完成来加快我的编码速度,但是它似乎并不建议使用某些方法。一个例子是Collectors.toMap - 当我输入.collect 但从不输入toMap 时,它会建议toSettoColletiontoList,这意味着我需要输入更多。

作为第一个问题,我可以解决此问题吗?作为一个更普遍的问题,我可以添加自己的自定义代码以在这些类型的情况下自动完成吗?

【问题讨论】:

  • 能否提供使用补全的代码示例?
  • list.stream().coll我希望有一个填充list.stream().collect(Collectors.toMap(的选项
  • 看起来像一个错误。请向 YouTrack 报告:youtrack.jetbrains.com/issues/IDEA

标签: intellij-idea java-stream


【解决方案1】:

每次尝试收集流时都能帮助我的一个技巧是使用具有预期类型的​​占位符变量。比如:

// just a placeholder variable with proper types, which I can remove later!
Map<String, String> tempMapVariable = someCollection.stream()
       .collect(
           // here it will suggest the .toMap(...)
           Collectors.toMap(i -> i.getKey(), i -> getValue())
       );

Set<String> tempSetVariable = someCollection.stream()
       .map(SomeCollection::mapperFn)
       .collect(
           // here it will suggest the .toSet()
           Collectors.toSet()
       );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-10
    • 2020-01-08
    • 1970-01-01
    • 2015-08-07
    • 2014-09-30
    • 2017-08-29
    • 1970-01-01
    相关资源
    最近更新 更多