Primer - Delegates in J#

Primer - Delegates in J#

 

In next couple of posts i will discuss about delegates in J# starting from basic introduction, different types, and finally discuss some examples around delegates.

 

Here is the first section of this primer...As always feel free to send in your comments, questions and feedback!

 

Delegates in J#

    Delegates are .NET version of the callback function. Unlike callback mechanism used in other platforms such as C/C++, delegates offer much more functionality. For example in Unmanaged C/C++, the address of a function is just a memory address. This address doesn’t carry along any information, such as the number of parameters the function expects, the types of these parameters, the functions return value type, and the functions calling convention. In short, unmanaged C/C++ callback functions are not type safe.

    However, Delegates in .NET ensures that the callback method is type safe and it also integrates the ability to call the multiple methods serially and support calling of static methods as well as instance methods.

    It needs to be noted that delegates are compiled into classes and hence the instances of delegates are treated like any other class instance.

Two Different Delegates types in J#

 

    It needs to be noted that in case of J# the binding of delegates is done at runtime (shall talk more on this later). It also needs to be noted that when we use the delegate and the multicast delegate keywords to declare single cast and multicast delegate in J#, the delegates that are created may be of the type com.ms.lang.Delegate or of the type System.Delegate depending on the declaration of the delegate.

 

In the next post, i will go in more details and talk about delegates derived from com.ms.lang.Delegate...