【问题标题】:Is IntelliJ showing wrong code completion?IntelliJ 是否显示错误的代码完成?
【发布时间】:2016-12-26 09:58:43
【问题描述】:

我在最新版本的 IntelliJ IDEA 中遇到了一些奇怪的行为。我有小型私有 java 库,当我尝试在其他项目中使用它时,IntelliJ 显示错误的方法参数名称。更多图片在这里: wrong IntelliJ code completion

请注意,当我这样做时,它会正常工作: good intellij code completion

我可以配置 IDE 使其像第二张图片那样显示,还是它是错误/预期行为?

编辑:

组合学是一个接口。 CombinatoricsImpl 是实现该接口的类,并具有 getCombinatorics 方法,该方法返回 CombinatoricsImpl 的新实例。

public static Combinatorics getCombinatorics() {
    return new CombinatoricsImpl();
}

接口(没有 javadoc):

public interface Combinatorics {

    double combinationsNonRepeating(int n, int k);

    double variationsNonRepeating(int n, int k);

    double permutationsNonRepeating(int n);

    double combinationsRepeating(int n, int k);

    double variationsRepeating(int n, int k);

    double permutationsRepeating(List<Integer> frequencies);
}

【问题讨论】:

  • 您在两个示例中没有使用相同的代码。可以在这里添加原始代码吗?
  • 这就是我认为的重点,在一种情况下它可以工作,而当我以另一种方式编写它时它就不起作用了。
  • 我明白,但添加代码会帮助我们帮助您
  • 这可能只是一个错误。请看here
  • 所以它可能是错误,检查它和Netbeans没有这样的问题。

标签: intellij-idea methods parameters


【解决方案1】:

getCombinatorics() 方法不返回 Combinatorics 类型的对象。这就是为什么它在第一张图片中不起作用的原因。

在第二张图片中,您将其转换为 Combinatorics 对象类型。所以它在第二张图片中工作。

我不认为这里的 ide 有什么问题。

【讨论】:

  • 该方法返回实现接口 Combinatorics 的类的实例(我在原始帖子中添加了一些代码)。在 Netbeans IDE 中这项工作没有问题,所以我认为这是 IDEA 中的错误。
猜你喜欢
  • 2015-02-01
  • 2016-06-10
  • 1970-01-01
  • 2020-06-22
  • 1970-01-01
  • 2016-10-09
  • 2011-09-27
  • 1970-01-01
  • 2018-01-23
相关资源
最近更新 更多