FunctionConverters

scala.jdk.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)

Attributes

Source:
FunctionConverters.scala
Graph
Supertypes
Self type

Members list

Concise view

Implicits

Inherited implicits

implicit def enrichAsJavaBiConsumer[T, U](sf: (T, U) => Unit): RichFunction2AsBiConsumer[T, U]
implicit def enrichAsJavaBiFunction[T, U, R](sf: (T, U) => R): RichFunction2AsBiFunction[T, U, R]
implicit def enrichAsJavaBiPredicate[T, U](sf: (T, U) => Boolean): RichFunction2AsBiPredicate[T, U]
implicit def enrichAsJavaBinaryOperator[T, A1, A2](sf: (T, A1) => A2)(implicit evA1: A1 =:= T, evA2: A2 =:= T): RichFunction2AsBinaryOperator[T]
implicit def enrichAsJavaDoubleBinaryOperator[A0, A1](sf: (A0, A1) => Double)(implicit evA0: A0 =:= Double, evA1: A1 =:= Double): RichFunction2AsDoubleBinaryOperator
implicit def enrichAsJavaDoubleConsumer[A0](sf: A0 => Unit)(implicit evA0: A0 =:= Double): RichFunction1AsDoubleConsumer
implicit def enrichAsJavaDoubleFunction[A0, R](sf: A0 => R)(implicit evA0: A0 =:= Double): RichFunction1AsDoubleFunction[R]
implicit def enrichAsJavaDoublePredicate[A0](sf: A0 => Boolean)(implicit evA0: A0 =:= Double): RichFunction1AsDoublePredicate
implicit def enrichAsJavaFunction[T, R](sf: T => R): RichFunction1AsFunction[T, R]
implicit def enrichAsJavaIntBinaryOperator[A0, A1](sf: (A0, A1) => Int)(implicit evA0: A0 =:= Int, evA1: A1 =:= Int): RichFunction2AsIntBinaryOperator
implicit def enrichAsJavaIntConsumer[A0](sf: A0 => Unit)(implicit evA0: A0 =:= Int): RichFunction1AsIntConsumer
implicit def enrichAsJavaIntFunction[A0, R](sf: A0 => R)(implicit evA0: A0 =:= Int): RichFunction1AsIntFunction[R]
implicit def enrichAsJavaIntPredicate[A0](sf: A0 => Boolean)(implicit evA0: A0 =:= Int): RichFunction1AsIntPredicate
implicit def enrichAsJavaIntToLongFunction[A0](sf: A0 => Long)(implicit evA0: A0 =:= Int): RichFunction1AsIntToLongFunction
implicit def enrichAsJavaIntUnaryOperator[A0](sf: A0 => Int)(implicit evA0: A0 =:= Int): RichFunction1AsIntUnaryOperator
implicit def enrichAsJavaLongBinaryOperator[A0, A1](sf: (A0, A1) => Long)(implicit evA0: A0 =:= Long, evA1: A1 =:= Long): RichFunction2AsLongBinaryOperator
implicit def enrichAsJavaLongConsumer[A0](sf: A0 => Unit)(implicit evA0: A0 =:= Long): RichFunction1AsLongConsumer
implicit def enrichAsJavaLongFunction[A0, R](sf: A0 => R)(implicit evA0: A0 =:= Long): RichFunction1AsLongFunction[R]
implicit def enrichAsJavaLongPredicate[A0](sf: A0 => Boolean)(implicit evA0: A0 =:= Long): RichFunction1AsLongPredicate
implicit def enrichAsJavaLongToIntFunction[A0](sf: A0 => Int)(implicit evA0: A0 =:= Long): RichFunction1AsLongToIntFunction
implicit def enrichAsJavaLongUnaryOperator[A0](sf: A0 => Long)(implicit evA0: A0 =:= Long): RichFunction1AsLongUnaryOperator
implicit def enrichAsJavaObjDoubleConsumer[T, A1](sf: (T, A1) => Unit)(implicit evA1: A1 =:= Double): RichFunction2AsObjDoubleConsumer[T]
implicit def enrichAsJavaObjIntConsumer[T, A1](sf: (T, A1) => Unit)(implicit evA1: A1 =:= Int): RichFunction2AsObjIntConsumer[T]
implicit def enrichAsJavaObjLongConsumer[T, A1](sf: (T, A1) => Unit)(implicit evA1: A1 =:= Long): RichFunction2AsObjLongConsumer[T]
implicit def enrichAsJavaSupplier[T](sf: () => T): RichFunction0AsSupplier[T]
implicit def enrichAsJavaToIntBiFunction[T, U](sf: (T, U) => Int): RichFunction2AsToIntBiFunction[T, U]
implicit def enrichAsJavaUnaryOperator[T, A1](sf: T => A1)(implicit evA1: A1 =:= T): RichFunction1AsUnaryOperator[T]
implicit def enrichAsScalaFromBiFunction[T, U, R](jf: BiFunction[T, U, R]): RichBiFunctionAsFunction2[T, U, R]