Hacker News new | ask | show | jobs
by ygra 3504 days ago
Java has default methods on interfaces instead. It's their take on the same issue, in a way. They considered the fact that with C#'s extension methods types not owned by the developer can be extended (as well as platform types) a problem and opted instead for a solution where someone who owns a type also controls its extensions. Default methods in Java are purely a way of adding stuff to interfaces in your API without breaking existing implementations (but also allowing future implementations to override those methods). C# on the other hand is merely a bit of syntactic sugar which can be confusing at times. (I have to admit not to be a fan of various libraries that add extension methods to integers and similar. It's not a good way of exposing an API in my eyes.)

TL;DR: Java has something similar, it just came from a different view of how the problem should be solved. Both approaches have advantages and drawbacks.