3 ms·
Brian Goetz's talk on Virtual Extension Methods at the JVM Language Summit 2011 was pretty interesting in this regard: http://medianetwork.oracle.com/media/sho
by eneveu 15y ago
Brian Goetz's talk on Virtual Extension Methods at the JVM Language Summit 2011 was pretty interesting in this regard:
http://medianetwork.oracle.com/media/show/16999 http://medianetwork.oracle.com/media/show/16999
He explains why adding lambdas isn't that straightforward, due to backward compatibility, but also because it wouldn't make sense to add lambdas without updating the standard APIs to benefit from these lambdas. Some of these APIs, such as the collections framework, are interface-based. Adding methods to an interface would break backward compatibility, which led them to Virtual Extension Methods.
For example, we could add a forEach method to the Collection interface without breaking backward compatibility:
interface Collection<T> {
// existing methods
void forEach(Block<T> block) default Collections.<T>forEach;
}
When not overriden, this virtual extension method would default to calling a static method, Collections.forEach(Collection<T>, Block<T>), thus preserving backward compatibility.