3 ms·
Apparently the closures will be based on the FCM (first class methods) proposal be Stephen Colebourne: http://docs.google.com/Doc?id=ddhp95vd_0f7mcns http://do
by bokchoi 17y ago
Apparently the closures will be based on the FCM (first class methods) proposal be Stephen Colebourne:
http://docs.google.com/Doc?id=ddhp95vd_0f7mcns http://docs.google.com/Doc?id=ddhp95vd_0f7mcns
- akeefer 17y agoFirst-class methods would be a win, but the syntax leaves a little bit to be desired. Closures would be much more of a syntactic eyesore if they A) had context-based type inference on the arguments, so that if I'm passing a closure to a method that expects (String, String) -> as its type I don't need to redeclare the variable types and B) allowed for embedded expressions rather than requiring them to be full function definitions with a "return" statement in there. Unfortunately, the FCM proposal doesn't allow either of those. To use their example, it should be much more like: Collections.sort(list, \str1, str2 -> str1.length() - str2.length()); instead of: Collections.sort(list, #(String str1, String str2) { return str1.length() - str2.length(); }); There's no technical reason you couldn't do the former in Java (and their proposal seems to infer the return type just fine?), but no one involved with the Java language seems to really value conciseness.
- bokchoi 17y agoNeal Gafter has updated his java closure info page with the infromation from Mark Reinhold's talk. http://www.javac.info/closures-v06a.html http://www.javac.info/closures-v06a.html http://www.jroller.com/scolebourne/entry/closures_in_jdk_7 http://www.jroller.com/scolebourne/entry/closures_in_jdk_7