3 ms·
Java can get into some weird cases with generics, super classes, and overriding. Joshua Bloc has some interesting ones in the fantastic (and horrific!) book, "J
by kjeetgill 8y ago
Java can get into some weird cases with generics, super classes, and overriding. Joshua Bloc has some interesting ones in the fantastic (and horrific!) book, "Java Puzzlers: Traps, Pitfalls, and Corner Cases".
For what it's worth, I think python's case is fairly simple and easy to remember.
Python objects can define two different methods for operator * : __mul__(self, b) and __rmul__(self, b). When you see A * B, try A.__mul__(B) if A has a __mul__. If the call throws NotImplemented (usually due to B's type) of if A did not hava a __mul__ call B.__rmul__().
I think that's actually much simpler that relying on types for dispatch since operators tend to be more "flexible" in their operand types than normal functions.