为什么 Netbeans 抱怨歧义而 Intellij 却没有
Why Netbeans complains about ambiguity while Intellij instead doesn't
我有一个 kotlin 数学库 Vec2i
class and primary constructor:
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 下的所有内容都可以编译并 运行s。我用单独的 java 项目测试了工件。
如果我切换 IDE,相同的工件不会 运行 在 java 项目中,Netbeans 抱怨两者之间的歧义。
为什么?
编辑:经过进一步分析,发现 Netbeans 抱怨是因为其中一个坐标是 int
,另一个是 Integer
。
在 Idea 上尝试同样的方法,它说:
cannot resolve constructor
那么,为什么用 (int, int)
或 (Integer, Integer)
调用构造函数没问题,但 (int, Integer)
没有解析为辅助构造函数并引起歧义?
在 oracles documentation 处,我们看到 Integer
是一个包含 int
的对象。
int
是基本类型,而 Integer
是对象。
您拥有的构造函数允许传递一对任一类型,但是当您同时传递这两种类型时,构造函数不知道要做什么。
详细信息this question有很好的细分。
我有一个 kotlin 数学库 Vec2i
class and primary constructor:
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 下的所有内容都可以编译并 运行s。我用单独的 java 项目测试了工件。
如果我切换 IDE,相同的工件不会 运行 在 java 项目中,Netbeans 抱怨两者之间的歧义。
为什么?
编辑:经过进一步分析,发现 Netbeans 抱怨是因为其中一个坐标是 int
,另一个是 Integer
。
在 Idea 上尝试同样的方法,它说:
cannot resolve constructor
那么,为什么用 (int, int)
或 (Integer, Integer)
调用构造函数没问题,但 (int, Integer)
没有解析为辅助构造函数并引起歧义?
在 oracles documentation 处,我们看到 Integer
是一个包含 int
的对象。
int
是基本类型,而 Integer
是对象。
您拥有的构造函数允许传递一对任一类型,但是当您同时传递这两种类型时,构造函数不知道要做什么。
详细信息this question有很好的细分。