Better Lambda support for JVx
I wrote about JVx and Java 8, Events and Lambdas some weeks ago.
It was a first test with JVx events and Lambdas and it was great to see that everything worked as expected, BUT not all JVx events were supported because not all listeners were defined as SAM type.
It was great to see that Lambdas were supported with our event handling implementation but it was a shame that only action events and some model events were really supported. So we started thinking
Our key listener was defined like this:
{
public void keyTyped(UIKeyEvent pKeyEvent);
public void keyPressed(UIKeyEvent pKeyEvent);
public void keyReleased(UIKeyEvent pKeyEvent);
}
The problem was that there were 2 methods too much. So we split the interface in 3 new interfaces:
- IKeyPressedListener
- IKeyReleasedListener
- IKeyTypedListener
Every listener has exactly one method, e.g.
{
public void keyPressed(UIKeyEvent pKeyEvent);
}
The new listener, for backwards compatibility, is this:
IKeyPressedListener,
IKeyReleasedListener
{
}
Our listener are handled from event handlers, like KeyHandler. The old implementation was:
{
public KeyHandler(String pListenerMethodName)
{
super(IKeyListener.class, pListenerMethodName);
}
}
(The handler creation with a method name wasn't really typesafe but it worked)
We refactored the handler a little bit and the result is:
{
public KeyHandler(Class<L> pClass)
{
super(pClass);
}
}
After some refactoring, our listeners were Lambda and backwards compatible, e.g.:
The next nightly build will contain all changes!
There are still some smaller todos, but Lambdas are well supported.