FunctionConverters

This object provides extension methods that convert between Scala and Java function types.

When writing Java code, use the explicit conversion methods defined in javaapi.FunctionConverters instead.

Using the .asJava extension method on a Scala function produces the most specific possible Java function type:

scala> import scala.jdk.FunctionConverters._ scala> val f = (x: Int) => x + 1 scala> val jf1 = f.asJava jf1: java.util.function.IntUnaryOperator = ...

More generic Java function types can be created using the corresponding asJavaXYZ extension method:

scala> val jf2 = f.asJavaFunction jf2: java.util.function.Function[Int,Int] = ... scala> val jf3 = f.asJavaUnaryOperator jf3: java.util.function.UnaryOperator[Int] = ...

Converting a Java function to Scala is done using the asScala extension method:

scala> List(1,2,3).map(jf2.asScala) res1: List[Int] = List(2, 3, 4)

Implicits

Inherited implicits

implicit def enrichAsJavaBiFunction[T, U, R](sf: (T, U) => R): RichFunction2AsBiFunction[T, U, R]
implicit def enrichAsJavaBinaryOperator[T, A1, A2](sf: (T, A1) => A2)(evA1: A1 =:= T, evA2: A2 =:= T): RichFunction2AsBinaryOperator[T]