Java Delegates?

markus picture markus · Sep 5, 2008 · Viewed 252.6k times · Source

Does the Java language have delegate features, similar to how C# has support for delegates?

Answer

Matt Sheppard picture Matt Sheppard · Sep 5, 2008

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 (@blueskyprojects.com)