I have to work with this huge monolithic code that was written in Java and has hundreds of code-repetitions like:
createButtonOne() {
...
public boolean pressed() {
doSomething();
return true;
}
}
createButtonTwo() {
...
public boolean pressed() {
doAnotherThing();
return true;
}
}
The code literally is the same apart from the function that is called, but it's rather annoying. Of course I could outsource great parts of the methods but this would cost me more time than doing it right with better tools. Or so I thought.
What I want to do is this:
ScalaButton buttonOne = new ScalaButton();
buttonOne.create("Label", Controller.doSomething());
ScalaButton buttonTwo = new ScalaButton();
buttonTwo.create("Label2", Controller.doAnotherThing());
Therefore I created ScalaButton as follows:
class ScalaButton
{
def create(label:String, action: () => Unit): Unit =
{
val button:Button = singletonCreator.createButton(label);
button.addListener(new InputListener()
{
override def pressed(...)
{
action()
true
}
}
}
The problem is that I've never done this call from Java and it says
found void, required scala.Function0
So I wonder, is it even possible to pass a java-method call to Scala this (or another) way? I haven't worked with Java in a few months and never used it alongside Scala in this way...