Closures in Java 7 [duplicate]

2019-01-13 12:57发布

This question already has an answer here:

I have heard that closures could be introduced in the next Java standard that is scheduled to be released somewhere around next summer.

What would this syntax look like?

I read somewhere that introducing closures in java is a bigger change than generic was in java 5. Is this true? pros and cons?

(By now we definitely know that closures not will be included in the next Java release)

OR

edit: http://puredanger.com/tech/2009/11/18/closures-after-all/ :D

edit2: Re-thinking JDK7: http://blogs.oracle.com/mr/entry/rethinking_jdk7

edit3: There’s not a moment to lose!: http://blogs.oracle.com/mr/entry/quartet

9条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-13 13:37

Unofortunately you will not find closure in Java 7. If you are looking for a lighter solution to have closure in java just now check out the lambdaj project:

http://code.google.com/p/lambdaj/

查看更多
Fickle 薄情
3楼-- · 2019-01-13 13:39

It really depends on what gets introduced, and indeed whether it will be introduced at all. There are a number of closure proposals of varying sizes.

See Alex Miller's Java 7 page for the proposals and various blog posts.

Personally I'd love to see closures - they're beautiful and incredibly helpful - but I fear that some of the proposals are pretty hairy.

查看更多
趁早两清
4楼-- · 2019-01-13 13:39

Note that a "function-type" is really a type under the proposal:

{int => boolean} evaluateInt;    //declare variable of "function" type
evaluateInt = {int x => x % 2 }; //assignment
查看更多
不美不萌又怎样
5楼-- · 2019-01-13 13:44

This is the java 7 features http://tech.puredanger.com/java7/#switch the examples are very usefull.

查看更多
Bombasti
6楼-- · 2019-01-13 13:50

closures will be annoyinglly verbose if there won't be any sort of type inference... :(

查看更多
Evening l夕情丶
7楼-- · 2019-01-13 13:53

Closures have some serious edge cases. I would say that Closures are a much more significant change than Generics and the later still has a number hairy edge cases. e.g. The Java Collections libraries cannot be written/compiled without warnings.

查看更多
登录 后发表回答