【问题标题】:Why Netbeans complains about ambiguity while Intellij instead doesn't为什么 Netbeans 抱怨模棱两可,而 Intellij 却没有
【发布时间】:2017-02-09 14:37:37
【问题描述】:

我有一个带有以下 Vec2i class and primary constructor 的 kotlin 数学库:

data class Vec2i(override var x: Int, override var y: Int) : Vec2t<Int>()

那么Vec2i 也有,在几个二级构造函数中,一个应该拦截所有其他的number types

constructor(x: Number, y: Number) : this(x.i, y.i)

Idea 下的所有内容都编译并运行。我用一个单独的 java 项目测试了这个工件。

如果我切换 IDE,相同的工件不会在 java 项目中运行,Netbeans 抱怨两者之间存在歧义。

为什么?

编辑:经过进一步分析,Netbeans 抱怨是因为其中一个坐标是int,另一个是Integer。 在 Idea 上尝试同样的方法,它说:

无法解析构造函数

那么,为什么用(int, int)(Integer, Integer) 调用协构函数很好,但(int, Integer) 没有解析为辅助构造函数并引起歧义?

【问题讨论】:

标签: java intellij-idea netbeans kotlin ambiguity


【解决方案1】:

oracles documentation,我们看到Integer 是一个包含int 的对象。

int 是原始类型,而Integer 是对象。

您拥有的构造函数允许传递任何一种类型,但是当您同时传递这两种类型时,构造函数不知道该怎么做。

更多信息this question 有一个很好的细分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 2015-03-17
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多