Is it possible to convert a Unit to a method of an anonymous class?
Instead of:
addSelectionListener(new SelectionListener{
def widgetSelected(SelectionEvent event): Unit = {
//...
}
}
To this:
addSelectionListener toAnonymousClass(classOf[SelectionListener], {
/* .. */
})
If there aren’t any libraries that can do this, how would I go about making one? Is it possible?
I believe the following implicit conversion should achieve the result you want:
It’ll automatically convert your function literals of type
SelectionEvent => Unitinto theSelectionListenerso you’ll be able to use theaddSelectionListenermethod like so: