It's not a secret anymore!
The moose likes Java in General and the fly likes Closures in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Closures in Java" Watch "Closures in Java" New topic

Closures in Java

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
OMG! I was frequently ignoring the e-mail about this Java Programming Cookbook promotion until I saw that the author was Herb Schildt. Hehehe.

Anyway, I would like to ask about "Closures". As I have heard, it's going to be(or already is) supported in Java 7? If so, what is it for? How does it help me as a developer? Could you provide an example?

From what I understand, a technical cookbook usually provides some ready-made codes? Is this what the book is about?


SCJP 1.5
Herb Schildt
Ranch Hand

Joined: Oct 01, 2003
Posts: 253
Hi Tim:

At this time I can't comment on what might or might not be in Java 7. Its just too early.

As to what's in my cookbook: Yes, there are a lot of code examples, lots of options, and lots of alternatives.

See the book's page on the McGraw-Hill website for the table of contents and Chapter 1.

An example recipe can be found on my website by clicking on the book's title on the homepage. Then, near the end of the book's description is a link to a sample recipe.

For my latest books on Java, including Introducing JavaFX 8 Programming, see
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Closures may be included in JDK 7, or JDK 8. There are a couple specific proposals for adding closures that are being discussed. Whether, how, and when they get added is yet to be determined. There is a prototype JDK available from Neal Gafter which supports closures. It's still a work in progress, with numerous bugs and bug fixes, and it's not an official Sun JDK. It's just one guy's demonstration of how closures could be implemented. Of course it's one guy who for several years was the primary author of Sun's javac compiler, and the proposal he's been working on is also supported by James Gosling, Gilad Bracha, and Peter von der Ahe. So it's not just one crazy guy in a garage. But ideas for how closures in Java should work are still evolving, and the final form (if there is one) may be somewhat different, and may stil be a few yearrs away. Recall that it took quite awhile for generics to make it into the language - this may be similar.

You may want to see this nice long talk from Neal, and this list of resources.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Closures in Java
It's not a secret anymore!