0

Let's say I have a Scala singleton object called HelloWorld with the following method:

def abacaba(m: (String) => Unit): Unit = {

}

When I try to call HelloWorld.abacaba from a Java class, my IDE (Intellij) tells me that it wants an object of type Function1<String, BoxedUnit>. This shouldn't be too hard; I can just implement the abstract methods and pass the anonymous class to scala.

Now, let's say I change abacaba to require a function accepting two strings:

def abacaba(m: (String, String) => Unit): Unit = {

}

Again, this isn't a problem; I just need to give Scala a Function2<String, String, BoxedUnit>. However, this doesn't work when I require that the function accept a very large number of arguments (from testing, I know that this must be more than 22):

def abacaba(m: (String, String, String, String, String, String, String, String, String, String, String, String,String, String,String, String,String, String,String, String, String, String, String) => Unit): Unit = {

}

Now, from Java it simply requests an Object. In this case (although I'm obviously never going to have to deal with this many parameters in the real world) how would I create an appropriate Scala function from my Java class? I'd prefer not to have to write utility methods in Scala or use Reflection.

ostrichofevil
  • 749
  • 7
  • 19

0 Answers0