Kotlin中的Hadoop上下文类型参数

编程入门 行业动态 更新时间:2024-10-21 11:34:06
本文介绍了Kotlin中的Hadoop上下文类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在Kotlin中实现Hadoop Mapper或Reducer时,我从编译器中得到一个有趣的矛盾。任何时候当你使用 Context 对象时,如果你不提供类型参数(< KEYIN,VALUEIN,KEYOUT,VALUEOUT> ),如果你提供类型参数,则表示没有期望的类型参数。任何想法发生在这里?

一个例子:

//给出预期的4种类型参数重写有趣的设置(上下文:Context?){ super.setup(context)} //给出没有类型参数预期覆盖乐趣设置(上下文:上下文< KeyIn,ValueIn,KeyOut,ValueOut> ;?){ super.setup(context)} < 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上下文类型参数

本文发布于:2023-11-14 09:29:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   参数   类型   Kotlin   Hadoop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!