Here is the class definition in java code:
public class WordCount {
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
context.write(word, one);
}
}
}
So what does this mean?
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable>
Why we need a “<>” here?
This is called “generics”. It allows you to add type parameters.
In this particular case, it means that
Mapis aMapperfor tuples of (LongWritable,Text,Text,IntWritable).A simpler example: suppose you have a Set. It could be a Set of integers, a set of strings, of MyClass instances…. this is where you use generics.
By declaring that a variable is of type
Set<Integer>, you specify that it is a set of Integers. If you’d just declare it as a Set, you would have to check that it only contained Integers yourself. By adding the type parameter<Integer>, the compiler can now do the type-checking.Generics are defined here in the Java Language Specification.