3 ms·
default methods in interfaces will more or less mimic the same behavior.(sorta like mixins its not exactly the same but yeah lol) class SomeClass implement
by randomguy7788 14y ago
default methods in interfaces will more or less mimic the same behavior.(sorta like mixins its not exactly the same but yeah lol)
class SomeClass implements Linq {}
public interface Linq {
public IEnumerable where(Func) { default implementation... }
public IEnumerable orderBy(Func) { default implementation... }
}
- lmm 14y agoThat's a good thing, but it doesn't let me add my own methods to existing classes - I can subclass and mixin an interface, but instances I get back from library methods won't have that extra interface.
- msgilligan 14y agoYou can do that with Groovy.
- lmm 14y agoOr with scala, and I do, but we're talking about Java 8 here.
- jmcqk6 14y agoC# really needs something similar to this. How many times have I implemented INotifyProgertyChanged and INotifyPropertyChanging. They're the exact same implementation every time. Now I've gone on to a base notify propery changed class that I can inherit from, but the mix-in approach, or the default implementation could be perfect.