I was reading some code and I saw this:
abstract class Accum {
/** Return the accumulated result. */
abstract int result();
/** Process and accumulate the value X. */
abstract void accum(int x);
/** Return the result of accumulating all of the values in vals. */
int reduce(int[] vals) {
for (int x : vals)
accum (x);
return result ();
}
}
How come reduce can call accum without referencing the object at hand with "this"? Doesn't this shorthand version of a function call work only for static methods? If this works, won't it blow up if both a static and non-static method have the same name?