S
Stefan Ram
Newsgroups: comp.lang.c,comp.lang.java.programmer
Followup-To: comp.lang.java.programmer
This is one place, where Java programming really shines.
In Java, you can't pass a call-back method to another method
at all, you can only pass a call-back object. So, say you
have a call
void qsort( base, nmemb, size, compar );
, then »compar« must be an object, and qsort will call its
»compare« method.
Now, what has this to do with auxiliary data?
An object has to be constructed, like
compar = new Compar( ... );
, and there, at the ellipsis "...", you can put whatever
auxiliary data you can dream of into your compar object.
No need for qsort to be aware of it, no means for qsort
to get in the way of this.
And this might be one reason against a certain kind
of closures in Java.
As soon as a method accepts a closure and in the case that
this is implemented in a way where a closure is a kind of
method, but /not/ a fully fledged object, this way to pass
auxiliary data won't work anymore.
Newsgroups: comp.lang.c,comp.lang.java.programmer
Followup-To: comp.lang.java.programmer
Followup-To: comp.lang.java.programmer
Ben Pfaff said:Personally I consider all four of these interfaces flawed because
they do not allow for any reasonable way to pass auxiliary data
to the callback functions. (I don't consider variables declared
at file scope to be reasonable in this context.)
This is one place, where Java programming really shines.
In Java, you can't pass a call-back method to another method
at all, you can only pass a call-back object. So, say you
have a call
void qsort( base, nmemb, size, compar );
, then »compar« must be an object, and qsort will call its
»compare« method.
Now, what has this to do with auxiliary data?
An object has to be constructed, like
compar = new Compar( ... );
, and there, at the ellipsis "...", you can put whatever
auxiliary data you can dream of into your compar object.
No need for qsort to be aware of it, no means for qsort
to get in the way of this.
And this might be one reason against a certain kind
of closures in Java.
As soon as a method accepts a closure and in the case that
this is implemented in a way where a closure is a kind of
method, but /not/ a fully fledged object, this way to pass
auxiliary data won't work anymore.
Newsgroups: comp.lang.c,comp.lang.java.programmer
Followup-To: comp.lang.java.programmer