When declaring matching and reducer classes as inner classes to another class, they must be declared static such that they are independent of the parent class.
Hadoop uses reflection to create an instance of the class for each map or to reduce the task. The newly created instance expects the constructor of null arguments (otherwise how does it know what to pass).
By declaring an internal mapper or decreasing a class without a static keyword, java compilation actually creates a constructor that expects an instance of the parent class to be passed during construction.
You should be able to see this by running the javap command against the generated class file.
In addition, the static keyword is not valid when using the parent class in the declaration (so you never see it at the top level, but only in child classes)
source share