Kotlin中的Hadoop上下文类型参数 [英] Hadoop Context type parameters in Kotlin
问题描述
Context
对象时,如果你不提供类型参数(< KEYIN,VALUEIN,KEYOUT,VALUEOUT>
),如果你提供类型参数,则表示没有期望的类型参数。任何想法发生在这里? 一个例子:
//给出预期的4种类型参数
重写有趣的设置(上下文:Context?){
super.setup(context)
}
//给出没有类型参数预期
覆盖乐趣设置(上下文:上下文< KeyIn,ValueIn,KeyOut,ValueOut> ;?){
super.setup(context)
}
$ c $指定映射器< KeyIn,ValueIn,KeyOut,ValueOut> .Context
使其能够编译,但由于 Context 是 Mapper
的内部类,不应该是的上下文类型当您指定要扩展的 Mapper
的类型时,它会隐含在Java中吗?
< Kotlin期望在 Mapper< KEYIN,VALUEIN,KEYOUT,VALUEOUT>
上具有4类型参数,而不是位于映射器< KEYIN,VALUEIN,KEYOUT,VALUEOUT> .Context
中的 Context
例如:
覆盖乐趣设置(上下文:Mappert< KeyIn, ValueIn,KeyOut,ValueOut> .Context?){
super.setup(context)
}
有可能隐含 Context
的类型参数。我建议在中创建一个问题。
When implementing a Hadoop Mapper or Reducer in Kotlin, I get an interesting contradiction from the compiler. Any time you use the Context
object, the compiler gives an error saying "4 type arguments expected" if you don't supply type arguments (<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
), and says "No type arguments expected" if you DO supply type arguments. Any ideas what's happening here?
An example:
// 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)
}
Specifying Mapper<KeyIn, ValueIn, KeyOut, ValueOut>.Context
makes it compile, but since Context
is an inner class of Mapper
, shouldn't the type of the Context
be implied when you specify the type of the Mapper
you're extending, as it is in Java?
解决方案 Kotlin is expecting "4 type arguments" on Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
and not on the Context
in Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>.Context
.
An example:
override fun setup(context: Mappert<KeyIn, ValueIn, KeyOut, ValueOut>.Context?) {
super.setup(context)
}
It is possible that the type arguments for Context
should/could be implied. I suggest creating an issue in the Kotlin YouTrack.
这篇关于Kotlin中的Hadoop上下文类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!