[483] in java-interest

home help back first fref pref prev next nref lref last post

Re: Function Pointers in Java?

daemon@ATHENA.MIT.EDU (Andrew Wason)
Fri Jun 23 19:16:55 1995

To: java-interest@java.sun.com
In-Reply-To: Message from fgreco@lehman.com (Frank Greco) 
   of "Fri, 23 Jun 95 16:31:17 -0400."   <9506232031.AA27714@cfdev1.lehman.com> 
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

home help back first fref pref prev next nref lref last post