Inspired by another question.
灵感来自另一个问题。
In fastutil
library there's IntArrayList
class which has a method with the following Java signature:
在fastutil库中有IntArrayList类,它有一个带有以下Java签名的方法:
public void push(Integer o)
From Kotlin it is seen as
来自Kotlin,它被视为
push(o: Int)
Is there a specific reason why it is Int
and not platform type Int!
?
是否有一个特定的原因,它是Int而不是平台类型Int !?
I expected it to be push(o: Int!)
at least because a method with the same signature defined in Java source within the project with Kotlin sources has Int!
as parameter type seen from Kotlin (even defined in different module, and even imported from jar of that module!).
我期望它是push(o:Int!),至少因为在项目中使用Kotlin源在Java源代码中定义的具有相同签名的方法具有Int!作为从Kotlin看到的参数类型(甚至在不同的模块中定义,甚至从该模块的jar中导入!)。
Also, the described behavior causes push(Integer o)
to conflict with push(int o)
(in the same class) which has Int
parameter legally -- they are both seen as push(o: Int)
. If there was Int!
for Integer
, there would be no conflict (I tried also to define this pair of methods in my code -- still works as I expect, there's Int!
).
此外,所描述的行为导致push(整数o)与具有Int参数的push(int o)(在同一类中)发生冲突 - 它们都被视为push(o:Int)。如果有Int!对于Integer,不存在冲突(我也尝试在我的代码中定义这对方法 - 仍然按照我的预期工作,有Int!)。
Kotlin version is 1.0.2
.
Kotlin版本是1.0.2。
Gradle dependency for fastutil
:
fastutil的gradle依赖:
compile group: 'it.unimi.dsi', name: 'fastutil', version: '7.0.12'
1 个解决方案
#1
9
I suspect that it is a kotlin compiler bug. Problem here is in interface IntStack
which is implemented by IntArrayList
:
我怀疑这是一个kotlin编译器错误。这里的问题是在IntStack接口中,由IntArrayList实现:
interface Stack<T> {
void push(T t);
}
interface IntStack extends Stack<Integer> {
void push(int i);
}
Kotlin sees only one method push(Int)
in interface IntStack
, or, more precisely, kotlin wrongly supposes that push(int i)
is an override of method push(T t)
.
Kotlin只在接口IntStack中看到一个方法push(Int),或者更确切地说,kotlin错误地认为push(int i)是方法推送(T t)的覆盖。
#1
9
I suspect that it is a kotlin compiler bug. Problem here is in interface IntStack
which is implemented by IntArrayList
:
我怀疑这是一个kotlin编译器错误。这里的问题是在IntStack接口中,由IntArrayList实现:
interface Stack<T> {
void push(T t);
}
interface IntStack extends Stack<Integer> {
void push(int i);
}
Kotlin sees only one method push(Int)
in interface IntStack
, or, more precisely, kotlin wrongly supposes that push(int i)
is an override of method push(T t)
.
Kotlin只在接口IntStack中看到一个方法push(Int),或者更确切地说,kotlin错误地认为push(int i)是方法推送(T t)的覆盖。