Kotlin 中的 Hadoop 上下文类型参数

Hadoop Context type parameters in Kotlin

在 Kotlin 中实现 Hadoop Mapper 或 Reducer 时,我从编译器那里得到了一个有趣的矛盾。任何时候你使用 Context 对象,如果你不提供类型参数 (<KEYIN, VALUEIN, KEYOUT, VALUEOUT>),编译器都会给出一个错误,提示“需要 4 个类型参数”,如果你提供,编译器会提示 "No type arguments expected"提供类型参数。知道这里发生了什么吗?

一个例子:

// 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)
}

指定 Mapper<KeyIn, ValueIn, KeyOut, ValueOut>.Context 使其编译,但由于 ContextMapper 的内部 class,Context 的类型不应该是当您指定要扩展的 Mapper 的类型时暗示,就像在 Java?

中一样

Kotlin 在 Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> 而不是 Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>.Context 中的 Context 上期望“4 个类型参数”。

一个例子:

override fun setup(context: Mappert<KeyIn, ValueIn, KeyOut, ValueOut>.Context?) {
    super.setup(context)
}

Context should/could 的类型参数可能是隐含的。我建议在 Kotlin YouTrack.

中创建一个问题