Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7632
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: simple method to simulate function pointers in java |
| Date | 2011-09-06 13:39 -0400 |
| Organization | The Wasteland |
| Message-ID | <nospam-5B77EE.13391706092011@news.aioe.org> (permalink) |
| References | <94e54cff-4dab-4c82-ade8-736174705e51@s2g2000vby.googlegroups.com> <4e657653$0$304$14726298@news.sunsite.dk> <39f8a144-5eaa-4b7f-b335-efb75539ff95@glegroupsg2000goo.googlegroups.com> |
In article <39f8a144-5eaa-4b7f-b335-efb75539ff95@glegroupsg2000goo.googlegroups.com >, Lew <lewbloch@gmail.com> wrote: > Arne Vajhøj wrote: > > Lino Ferrentino wrote: > >> Maybe there are other methods... I use this: > >> > >> [code omitted] > >> > >> to call the callback > >> > >> my_callback.f(42); > >> > >> > >> For each function pointer type we create an interface. > > > > It is perfectly valid. > > > > You need to note two things: > > 1) the codes is not following Java coding convention > > 2) it is based on an assumption that all functions with > > the same signature are interchangeable - that is not > > very type safe > > The Java idiom is to use a functor, typically a > single-abstract-method (SAM) interface, and pass an instance of that > functor type to the object needing a callback or similar method. The > object implementing the functor interface is the called-back object. > > And as Arne says, do follow the coding conventions. Your code was > nearly impenetrable. You name things by purpose in Java, not by > implementation type. > > Roughly (very roughly)_speaking, the functor pattern is something like: > > [code omitted] A related example of this widely used pattern may be found in `EventListenerList` [1], which adds a measure of type safety by using a class literal as a runtime type-token [2]. [1]<http://download.oracle.com/javase/7/docs/api/javax/swing/event/EventListenerList.html> [2]<http://download.oracle.com/javase/tutorial/extra/generics/literals.html> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
simple method to simulate function pointers in java Lino Ferrentino <lino.ferrentino@gmail.com> - 2011-09-02 01:54 -0700
Re: simple method to simulate function pointers in java Mayeul <mayeul.marguet@free.fr> - 2011-09-02 11:56 +0200
Re: simple method to simulate function pointers in java Patricia Shanahan <pats@acm.org> - 2011-09-02 03:17 -0700
Re: simple method to simulate function pointers in java Lino Ferrentino <lino.ferrentino@gmail.com> - 2011-09-02 05:11 -0700
Re: simple method to simulate function pointers in java Arne Vajhøj <arne@vajhoej.dk> - 2011-09-05 21:21 -0400
Re: simple method to simulate function pointers in java Roedy Green <see_website@mindprod.com.invalid> - 2011-09-02 07:43 -0700
Re: simple method to simulate function pointers in java Arne Vajhøj <arne@vajhoej.dk> - 2011-09-05 21:24 -0400
Re: simple method to simulate function pointers in java Lew <lewbloch@gmail.com> - 2011-09-05 19:00 -0700
Re: simple method to simulate function pointers in java "John B. Matthews" <nospam@nospam.invalid> - 2011-09-06 13:39 -0400
csiph-web