[488] in java-interest
Re: Function Pointers in Java?
daemon@ATHENA.MIT.EDU (Jonathan Payne)
Fri Jun 23 21:13:47 1995
Date: Fri, 23 Jun 1995 17:11:45 -0700
From: jpayne@starwave.com (Jonathan Payne)
To: aw@bae.bellcore.com
Cc: java-interest@java.sun.com
In-Reply-To: <9506232252.AA09460@jello> (message from Andrew Wason on Fri, 23 Jun 95 18:52:31 -0400)
Everything you say here is true.
But I think it would nice to have function pointers. It would be
especially nice for implementing things like keymaps, for say, a text
editor.
> Date: Fri, 23 Jun 95 18:52:31 -0400
> From: Andrew Wason <aw@bae.bellcore.com>
> fgreco@lehman.com (Frank Greco) writes:
> >
> > Since there are no pointers in Java, how does one handle function pointers?
>
> There aren't functions either, only methods.
>
> If you're trying to implement a callback mechanism, you could
> define a new interface that defines your callback method and then
> the user could create classes that implement that interface and
> pass an instance of that class to your callback registration
> method. When you need to call back, call the method defined by
> the interface on the users object.
>
> e.g. your interface could be:
>
> public interface Callback {
> public abstract void Notify();
> }
>
> Your callback registration method could be:
>
> public Register(Callback cb) {
> // save cb somewhere
> }
>
> When you need to call the callback, do:
>
> cb.Notify();
>
> The user would implement Callback and register an instance:
>
> public class MyClass implements Callback {
> public void Notify() {
> // implement the callback
> }
> }
>
> foo.Register(new MyClass());
>
>
> Andrew
>
> _______________________________________________________________________________
>
> Andrew Wason Bell Communications Research
> aw@bae.bellcore.com Piscataway, NJ
> -
> Note to Sun employees: this is an EXTERNAL mailing list!
> Info: send 'help' to java-interest-request@java.sun.com
>
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com