I’m looking at “WordCount”, the hello world example for Hadoop, and it contains the following method:
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
context.write(key, new IntWritable(sum));
}
}
I must be misinterpreting what I am reading. I read this asa generic class called Reduce, which extends base class Reducer, with some generic types. Coming from C#, the signature would not be allowed, because there are two instances of Text, and the compiler would not know how to map the arguments appropriately.
Could someone explain this unfamiliar syntax?
Edit:
This is an example of Generics, however, in this form, the actual types to be used have been set in the declaration. The class Reduce, is not generic, but Reducer is, and we have set parameters A, B, C, and D.
Reduceris apparently typed as<A, B, C, D>. Just because A and C happen to be provided by the same type doesn’t make it impossible (and should work in C# as far as I know).Edit: to clarify — you can have a method with more than one parameter of the same type:
public void foo(String a, String b). One wouldn’t say this was ambiguous. Generic types are parameters on the class, and can be used in a similar fashion. Think of aMap<String, String>— you may have one String that represents an ID pointing to another String as a username.