Results 1 to 15 of 15

Thread: Closures

  1. #1
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default Closures

    Does anyone using closures in real projects? It will be good to hear about advantages and disadvantages of closures.
    Try Controls4J - Advanced Swing Components.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    java doesn't support closures. But its comming to JDK7.
    advantage: code looks clean
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Ya current versions are not supported.

    And also, I'm not sure how many people use it with JDK7.

  4. #4
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    But as I know, closures can be used with current versions.

    IMHO. most of people can't use properly even standard language features. They should not use closures while they don't understand that they want to use this feature.
    Try Controls4J - Advanced Swing Components.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    Yes, but you can find implementation here.
    Try Controls4J - Advanced Swing Components.

  7. #7
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    That's appears to be a Java 7 prototype, which most people won't have seen.

    Advantages: cleaner code and higher-level functional abstraction
    Disadvantages: nightmare to write compilers for it
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by OrangeDog View Post
    Advantages: cleaner code and higher-level functional abstraction
    Even without use of Closures we can achieve this with well formed programming practice.

  9. #9
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Quote Originally Posted by Eranga View Post
    Even without use of Closures we can achieve this with well formed programming practice.
    You can't return a function cleanly in Java 6. The only way is to return new class instances that implement an interface. Currying is impossible without closures.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by OrangeDog View Post
    You can't return a function cleanly in Java 6. The only way is to return new class instances that implement an interface. Currying is impossible without closures.

    Ya agreed with you. I think that's why we have interface and so on.

  11. #11
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Last I heard (Sun UK Developer Update in March), closures won't be in Java 7 because they couldn't get a consensus on the implementation.

    Some useful information here

    www.infoq.com/news/2009/01/java7-updated

    (InfoQ: Java 7 Roadmap Updated: Reactions)

    Stupid forum software won't let me include proper links :mad:

  12. #12
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Quote Originally Posted by Eranga View Post

    Ya agreed with you. I think that's why we have interface and so on.
    No, interfaces aren't designed for that. Hard-coding your own closures is messy in any OO language.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I think better to look at the Java doc about those things first myself. Actually I don't think I want to use them even in future in my developments. ;) I'' get here if anything hang on with me.

  14. #14
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    I'm open to it. It convient instead of using anomyous innner classes such as:
    new Thread(new Runnable{ public void run(){....
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  15. #15
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Less useful there, major use would be for comparators and iterators and the like.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •