Kotlin中的Hadoop上下文类型参数
在Kotlin中实现Hadoop映射器或Reducer时,我从编译器中得到了一个有趣的矛盾。每当您使用Kotlin中的Hadoop上下文类型参数,hadoop,kotlin,Hadoop,Kotlin,在Kotlin中实现Hadoop映射器或Reducer时,我从编译器中得到了一个有趣的矛盾。每当您使用上下文对象时,如果您不提供类型参数(),编译器都会给出一个错误,说“需要4个类型参数”,如果您提供类型参数,编译器会说“不需要类型参数”。知道这里发生了什么吗 例如: // gives "4 type arguments expected" override fun setup(context: Context?) { super.setup(context) } // gives "
上下文
对象时,如果您不提供类型参数(
),编译器都会给出一个错误,说“需要4个类型参数”,如果您提供类型参数,编译器会说“不需要类型参数”。知道这里发生了什么吗
例如:
// gives "4 type arguments expected"
override fun setup(context: Context?) {
super.setup(context)
}
// gives "No type arguments expected"
override fun setup(context: Context<KeyIn, ValueIn, KeyOut, ValueOut>?) {
super.setup(context)
}
override fun setup(context: Mappert<KeyIn, ValueIn, KeyOut, ValueOut>.Context?) {
super.setup(context)
}
//提供“需要4个类型参数”
覆盖乐趣设置(上下文:上下文?){
super.setup(上下文)
}
//提供“不需要类型参数”
覆盖乐趣设置(上下文:上下文?){
super.setup(上下文)
}
指定Mapper.Context
可以使它进行编译,但是既然Context
是Mapper
的一个内部类,那么当您指定要扩展的Mapper
的类型时,是否应该暗示Context
的类型,就像在Java中一样?Kotlin需要“4个类型参数”在Mapper
上,而不是在Mapper.Context
中的Context
上
例如:
// gives "4 type arguments expected"
override fun setup(context: Context?) {
super.setup(context)
}
// gives "No type arguments expected"
override fun setup(context: Context<KeyIn, ValueIn, KeyOut, ValueOut>?) {
super.setup(context)
}
override fun setup(context: Mappert<KeyIn, ValueIn, KeyOut, ValueOut>.Context?) {
super.setup(context)
}
覆盖乐趣设置(上下文:Mappert.context?){
super.setup(上下文)
}
Context
的类型参数可能应该/可能是隐含的。我建议在中创建一个问题。对于那些感兴趣的人来说,Kotlin似乎没有在内部类中捕获任何泛型。我在YouTrack上制作了一张已分配的票证:内部类中的泛型问题有一张父票证: