Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7602

Re: simple method to simulate function pointers in java

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Date Mon, 05 Sep 2011 21:24:22 -0400
From Arne Vajhøj <arne@vajhoej.dk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: simple method to simulate function pointers in java
References <94e54cff-4dab-4c82-ade8-736174705e51@s2g2000vby.googlegroups.com>
In-Reply-To <94e54cff-4dab-4c82-ade8-736174705e51@s2g2000vby.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Lines 53
Message-ID <4e657653$0$304$14726298@news.sunsite.dk> (permalink)
Organization SunSITE.dk - Supporting Open source
NNTP-Posting-Host 72.192.23.141
X-Trace news.sunsite.dk DXC=1k0\PYSo\acE`KPf6Y4mAkYSB=nbEKnkkTUCR5gQKU5iJPe3\kP5EUaKBm9cfh9BSdM2;kT<[:>[ag7W3XHX2Ube?Qgn@;PaJTg
X-Complaints-To staff@sunsite.dk
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7602

Show key headers only | View raw


On 9/2/2011 4:54 AM, Lino Ferrentino wrote:
> Maybe there are other methods... I use this:
>
> public final class b_callbacks {
>
>      private b_callbacks(){
>      }
>
>
>      public static interface void_f_void{
> 	public void f();
>      }
>
>      public static interface void_f_int{
> 	public void f(int i);
>      }
>
>
> }
>
> ----
>
> when I want to use a function pointer
>
> import b_callbacks.void_f_int;
>
> private void_f_int my_callback;
>
> my_callback = new void_f_int(){
>   public void f(int i){
>     //code
>   }
> };
>
> 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

Arne

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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