<bdo id='CSyni'></bdo><ul id='CSyni'></ul>
    1. <small id='CSyni'></small><noframes id='CSyni'>

      1. <tfoot id='CSyni'></tfoot>
        <i id='CSyni'><tr id='CSyni'><dt id='CSyni'><q id='CSyni'><span id='CSyni'><b id='CSyni'><form id='CSyni'><ins id='CSyni'></ins><ul id='CSyni'></ul><sub id='CSyni'></sub></form><legend id='CSyni'></legend><bdo id='CSyni'><pre id='CSyni'><center id='CSyni'></center></pre></bdo></b><th id='CSyni'></th></span></q></dt></tr></i><div id='CSyni'><tfoot id='CSyni'></tfoot><dl id='CSyni'><fieldset id='CSyni'></fieldset></dl></div>

        <legend id='CSyni'><style id='CSyni'><dir id='CSyni'><q id='CSyni'></q></dir></style></legend>

        为什么将 Mapper 和 Reducer 类声明为静态的?

        时间:2023-09-26

              <tfoot id='HLzxZ'></tfoot>
                <tbody id='HLzxZ'></tbody>
              <legend id='HLzxZ'><style id='HLzxZ'><dir id='HLzxZ'><q id='HLzxZ'></q></dir></style></legend>

              <small id='HLzxZ'></small><noframes id='HLzxZ'>

              • <bdo id='HLzxZ'></bdo><ul id='HLzxZ'></ul>
                <i id='HLzxZ'><tr id='HLzxZ'><dt id='HLzxZ'><q id='HLzxZ'><span id='HLzxZ'><b id='HLzxZ'><form id='HLzxZ'><ins id='HLzxZ'></ins><ul id='HLzxZ'></ul><sub id='HLzxZ'></sub></form><legend id='HLzxZ'></legend><bdo id='HLzxZ'><pre id='HLzxZ'><center id='HLzxZ'></center></pre></bdo></b><th id='HLzxZ'></th></span></q></dt></tr></i><div id='HLzxZ'><tfoot id='HLzxZ'></tfoot><dl id='HLzxZ'><fieldset id='HLzxZ'></fieldset></dl></div>
                • 本文介绍了为什么将 Mapper 和 Reducer 类声明为静态的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这可能表明我缺乏对 Java 的理解,但我想知道为什么在大多数 MapReduce 程序中,mapper 和 reducer 类被声明为静态的?

                  This is likely showing my lack of Java understanding but I am wondering why in most MapReduce programs mapper and reducer classes are declared as static?

                  推荐答案

                  当将 mapper 和 reducer 类声明为另一个类的内部类时,必须将它们声明为 static,以便它们不依赖于父类.

                  When declaring mapper and reducer classes as inner classes to another class, they have to be declared static such that they are not dependent on the parent class.

                  Hadoop 使用反射为每个运行的 map 或 reduce 任务创建类的实例.创建的新实例需要一个零参数构造函数(否则它怎么知道要传递什么).

                  Hadoop uses reflection to create an instance of the class for each map or reduce task that runs. The new instance created expects a zero argument constructor (otherwise how would it know what to pass).

                  通过在没有 static 关键字的情况下声明内部 mapper 或 reduce 类,java 编译实际上创建了一个构造函数,该构造函数期望在构造时传入父类的实例.

                  By declaring the inner mapper or reduce class without the static keyword, the java compile actually creates a constructor which expects an instance of the parent class to be passed in at construction.

                  您应该能够通过对生成的类文件运行 javap 命令来看到这一点

                  You should be able to see this by running the javap command against the generated classfile

                  另外,static 关键字在父类声明中使用时无效(这就是为什么您在顶层看不到它,而只在子类中看到它的原因)

                  Also, the static keyword is not valid when used in a parent class declaration (which is why you never see it at the top level, but only in the child classes)

                  这篇关于为什么将 Mapper 和 Reducer 类声明为静态的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:不推荐使用 MapReduceBase 和 Mapper 下一篇:Java 8 从一对多分组

                  相关文章

                  最新文章

                    <bdo id='x8zTb'></bdo><ul id='x8zTb'></ul>
                • <legend id='x8zTb'><style id='x8zTb'><dir id='x8zTb'><q id='x8zTb'></q></dir></style></legend>

                  <small id='x8zTb'></small><noframes id='x8zTb'>

                • <i id='x8zTb'><tr id='x8zTb'><dt id='x8zTb'><q id='x8zTb'><span id='x8zTb'><b id='x8zTb'><form id='x8zTb'><ins id='x8zTb'></ins><ul id='x8zTb'></ul><sub id='x8zTb'></sub></form><legend id='x8zTb'></legend><bdo id='x8zTb'><pre id='x8zTb'><center id='x8zTb'></center></pre></bdo></b><th id='x8zTb'></th></span></q></dt></tr></i><div id='x8zTb'><tfoot id='x8zTb'></tfoot><dl id='x8zTb'><fieldset id='x8zTb'></fieldset></dl></div>

                  <tfoot id='x8zTb'></tfoot>