C# Delegates in Java

Here is a way to get something like C# Delegates in Java. A delegate is basically an object representing a bound method. I didn’t realize that C# had this, and it’s a very nice feature that I wish Java had. The implementation the authors have done is pretty good, but it would be nice to have the same kind of syntactic sugar that C# provides here. Maybe J2SE 1.6?

One thought on “C# Delegates in Java”

  1. Chris Nokleberg wrote a bit of history about C# Delegates vs. Java:
    which raises the point that we will likely never have delegates in Java, because of a Sun/Microsoft turf war. (Do we really want Sun to lead the Java world?)

    On a more positive note, he gave a pointer to CGLIB, which also provides delegates but through bytecode generation rather than reflection:

    That would certainly be faster for delegates that will be called frequently.

Comments are closed.