Can a class be used as an argument to a method?
I’ve been trying to understand the Hadoop MapReduce program for several days. I saw the statement below.
conf.setInputFormat(TextInputFormat.class);
I do not question the legality of this statement, since there are no problems with the operation of the program. Can someone explain why TextInputFormat.class is an object of type input and not a text input format? Can I also use the same convention for other methods? Under what circumstances does it fail?
This is the signature of setinputformat.
<http://hadoop.apache.org/docs/current/api/org/apache/hadoop/mapred/JobConf.html#setInputFormat(java.lang.Class)>
setInputFormat(Class<? extends InputFormat> theClass)
Set the InputFormat implementation for the map-reduce job.
Solution
Mappers and reducers need to know the kind of format. They don’t need an actual handle. Each mapper/reducer will use that class
to instantiate their own usage reflections. This is the difference between giving someone a hammer and telling someone to use a hammer. Your specific example is the instruction to use a hammer.