Does the Java language have delegate features, similar to how C# has support for delegates?
-
Short story: no.
From Patrick -
No, but here's an article on how to sort of implement them.
From Blorgbeard -
As it says in what Patrick linked you want to use inner classes instead.
From SCdF -
Not really, no.
You may be able to achieve the same effect by using reflection to get Method objects you can then invoke, and the other way is to create an interface with a single 'invoke' or 'execute' method, and then instantiate them to call the method your interested in (i.e. using an anonymous inner class).
You might also find this article interesting / useful : A Java Programmer Looks at C# Delegates
From Matt Sheppard -
While it is nowhere nearly as clean, but you could implement something like C# delegates using a Java Proxy.
From John Meagher -
I have implemented callback/delegate support in Java using reflection. Details and working source are available on my website.
From Software Monkey -
Have you read this?
http://www.cutthecrap.biz/software/delegates.html
From Michael
0 comments:
Post a Comment