Skip to main content

language: proper closures

10 replies [Last post]
jtr
Offline
Joined: 2003-06-10
Points: 0

For syntatic sugar, I'd be most interested in seeing closures. This situation has gotten better with JDK 1.5, but using groovy brought back the good feeling of anonymous closures. It'd be great if Java had this too.

I've read that closures weren't included in the original JDK's because C++ programmers (hey I was one once too!) didn't want stuff allocated on the heap without a explicit "new". Well, with garbage collector performance in 2004, that's a little less of an issue.

Performance problems could be mitigated simply by not using these closures (a compile time could let developers know about variables which are implicitly being allocated on the heap).

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
eirikma
Offline
Joined: 2004-04-23
Points: 0

There is a similar discussion under the "methods as first class objects" as well.

zander
Offline
Joined: 2003-06-13
Points: 0

Note the duplication of topic see:

http://forums.java.net/jive/thread.jspa?threadID=87

patrikbeno
Offline
Joined: 2004-10-11
Points: 0

I am interested, it seems like it would be very helpful. It is of course nothing we couldn't do with anonymous classes, but it may decrease code verbosity if implemented properly.

Do you have any idea how this cound be implemented in Java? I mean, try to suggest syntax.

zander
Offline
Joined: 2003-06-13
Points: 0

Did you look at how Groovy does it? I think they already have it nailed.

patrikbeno
Offline
Joined: 2004-10-11
Points: 0

Yes i did. I am think how we would do it in Java. Groovy syntax is not compatible with Java concepts.

cowwoc
Offline
Joined: 2003-08-24
Points: 0

Could you please define closures? I am not familiar with the concept.

jtr
Offline
Joined: 2003-06-10
Points: 0

it's probably best to experience them yourself. Please visit the groovy website at http://groovy.codehaus.org/Closures

Think anonymous inner classes, but you don't need to use final.

tsinger
Offline
Joined: 2003-06-10
Points: 0

Who really needs that? I never had a problem with interfaces/anonymous classes.

Tom

jw8jw8
Offline
Joined: 2003-08-01
Points: 0

I need them, I've had problems with anonymous classes many times.

tsinger
Offline
Joined: 2003-06-10
Points: 0

[b]What[/b] problems?