The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Alexander Schunk

Alexander Schunk is an graduate BA student of Comuter Science at the University of Applied Sciences. He writes German textbooks on Java Technology and is the owner of the java.net project JDKGUITools which provides GUI versions of SDK command-line tools. Also he is member of the OpenJDK Project and frequntly posts Blogs on new insights of the OpenJDK compiler and the Java Runtime. Homepage: www.alexanderschunk.de (always uder development :) )

 

Alexander Schunk's blog

Java Closures: Functions or Objects?

Posted by alexanderschunk on January 23, 2008 at 11:56 AM PST

Java Closures? What are they?

The question wheather closures are functions or objects came to my mind when reading several proposals concerning on closures. It looks like most authors regard them as both - functions and objects but giving not a real and concrete distinction in what case a closure is a function - or functional object - and an object.

For example in Neil Gafters vision for closures, closures seem to be both functions or an anonymous function or method and objects - or even classes beecause its possible to extend a class or template from a closure.

I think, if we follow the traditional closure syntax and usage - like in lisp or Perl where closures are regarded as procedures or sub routines. I have difficulties to imagíne a case where it makes sense or its practical to have the ability to extend a template or class from a closure as follows:

class MyClass
extends 
{ int x, int y => int }

or any such nomenclature. If a closure is nothing more than an anonymous function why do we need extend them to real object types? Is it just enough to have a short hand for anonymous methods in which the BGGA Syntax would just be enough?

I even have diffiuclty to see what a class or object like:

{int x, int y => int }

in the above example would describe or what power closures provide to describe real world entitities. To me closures are to abstract to describe real world entities i would only allow them as a short hand for anonymous functions or methods as used in Lisp or Perl.

Also it would make sense to allow closures as parameters for normal methods i.g:

int myClosureMethod(int x, {int y, int z = > int }){
 //something
}

but dont apply them on classes or templates because templates are already a very powerful feature to describe real world entities.

Comments
Comments are listed in date ascending order (oldest first)

RED EYE OWNZ - by Z4i0n

RED EYE OWNZ - by Z4i0n

RED EYE OWNZ - by Z4i0n

RED EYE OWNZ - by Z4i0n
Syndicate content