Is there any way that I can add delegate features into Java by a library for example I write add library that add delegate as keyword and handle delegate features like C#
delegate void SendMessageDelegate(Message message);
void SendMessage(SendMessageDelegate sendMessageDelegateReference)
{
sendMessageDelegateReference(new Message("hello this is a sample message"));
}
void HandleSendMessage(Message message)
{
Sender.Send(message);
}
In general, my question is: is there any way to add my new features such as:
- late binding
- delegates
- events like C#
- properties
by one or more libraries into Java instead of create a new compiler such as groovy or scala?
The simple answer is no. Not with any reasonable amount of work.
However you can probably implement some or all of those features using the existing Java tools (or find a library that already does it).
You wouldn't be able to add a new keyword to the language - but it's amazing what you can do with creative use of annotations, generics, etc.
Google found this: https://today.java.net/pub/a/today/2004/10/06/compiler.html
I've no idea how good it is.