What is the upside of checking isa when you're deliberately trying to cast a wide net?
Good point. However with the error message example, IMO checking isa is simplier than checking can for each method you intend to use, especially when you start getting into a lot of methods (these example interfaces are very simple). Also when an interface is implemented, it is not just about the names of methods, but also the arguments they expect, and values they return. The interface must be implemented as a whole, and not just in parts. Whose to say that hasNext and next should behave the same across all classes? However, if they both belong to a specific interface, then you know they follow that interfaces guidelines/contract/philosophy.
To be honest, the really nice benefits of interface polymorphism come when the language has stricter object type checking and method dispatch based on the full method signature, not just the name. Then you get compile time errors instead.
In reply to Re^6: Solving the SUPER problem in Mixins with String Eval
by stvn
in thread Solving the SUPER problem in Mixins with String Eval
by simonm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |