comp.lang.ada
 help / color / mirror / Atom feed
From: Hyman Rosen <hymie@prolifics.com>
Subject: Re: Dummy
Date: 2000/02/07
Date: 2000-02-07T23:47:27+00:00	[thread overview]
Message-ID: <t7vh40shgi.fsf@calumny.jyacc.com> (raw)
In-Reply-To: 873dr4pz44.fsf@deneb.cygnus.argh.org

Florian Weimer <someone@deneb.cygnus.argh.org> writes:
> This prints `3' and `4', doesn't it?  Cool.  I didn't know that Java
> supports class closures.  Now Java only needs operator overloading
> and some syntactic sugar for dispatching by name and introspection,
> and Java will become my favorite scripting language. ;)

Actually, I'm wrong about this. I was over-ambitious. The following
similar code does work, though. The trick is that the "closures" are
fake - behind the scenes, Java copies the referenced locals into the
local class, and only lets you do this with "final" variables.

class a
{
	interface i
	{
		int get();
		void set(int n);
	}
	class my_int implements i
	{
		int val;
		public int get() { return val; }
		public void set(int n) { val = n; }
	}
	i local_ref()
	{
		final my_int local = new my_int();
		return new i () {
			public int get() { return local.get(); }
			public void set(int n) { local.set(n); }
		};
	}
	public static void main(String[] v)
	{
		a my_a = new a();
		i i1 = my_a.local_ref();
		i i2 = my_a.local_ref();
		i1.set(3);
		i2.set(4);
		System.out.println(i1.get());
		System.out.println(i2.get());
	}
}




  reply	other threads:[~2000-02-07  0:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-02  0:00 Dummy Simic_10111
     [not found] ` <3898C380.BC01EC03@earthlink.net>
2000-02-03  0:00   ` Dummy Hyman Rosen
2000-02-03  0:00     ` Dummy Tucker Taft
2000-02-04  0:00       ` Dummy Florian Weimer
2000-02-04  0:00         ` Dummy Robert A Duff
2000-02-05  0:00           ` Dummy Jean-Pierre Rosen
2000-02-10  0:00             ` Dummy Geoff Bull
2000-02-07  0:00         ` Dummy Hyman Rosen
2000-02-07  0:00           ` Dummy Florian Weimer
2000-02-07  0:00             ` Hyman Rosen [this message]
2000-02-04  0:00       ` Dummy Robert A Duff
2000-02-03  0:00     ` Dummy Gautier
2000-02-03  0:00       ` Dummy Hyman Rosen
2000-02-03  0:00     ` Dummy Larry Kilgallen
2000-02-03  0:00       ` Dummy Hyman Rosen
2000-02-03  0:00         ` Dummy Larry Kilgallen
     [not found] ` <389c50a6.14707859@news.flash.net>
2000-02-04  0:00   ` Dummy Marin D. Condic
  -- strict thread matches above, loose matches on Subject: below --
2000-01-11  0:00 Dummy Simic_10111
2000-01-11  0:00 ` Dummy Ehud Lamm
2000-01-11  0:00 ` Dummy Gautier
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox