Packages

o

scala.jdk

FunctionConverters

object FunctionConverters

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

The explicit conversion methods defined here are practical when writing Java code. For Scala code, it is recommended to use the extension methods defined in FunctionConverters.Ops.

Using the .asJava extension method (from FunctionConverters.Ops) on a Scala function produces the most specific possible Java function type:

scala> import scala.jdk.FunctionConverters; import FunctionConverters.Ops._
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)
Source
FunctionConverters.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FunctionConverters
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Test two objects for inequality.

    Test two objects for inequality.

    returns

    true if !(this == that), false otherwise.

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Equivalent to x.hashCode except for boxed numeric types and null.

    Equivalent to x.hashCode except for boxed numeric types and null. For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them. For null returns a hashcode where null.hashCode throws a NullPointerException.

    returns

    a hash value consistent with ==

    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).

    The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Cast the receiver object to be of type T0.

    Cast the receiver object to be of type T0.

    Note that the success of a cast at runtime is modulo Scala's erasure semantics. Therefore the expression 1.asInstanceOf[String] will throw a ClassCastException at runtime, while the expression List(1).asInstanceOf[List[String]] will not. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested type.

    returns

    the receiver object.

    Definition Classes
    Any
    Exceptions thrown

    ClassCastException if the receiver object is not an instance of the erasure of type T0.

  5. def asJavaBiConsumer[T, U](sf: (T, U) => Unit): BiConsumer[T, U]
    Annotations
    @inline()
  6. def asJavaBiFunction[T, U, R](sf: (T, U) => R): BiFunction[T, U, R]
    Annotations
    @inline()
  7. def asJavaBiPredicate[T, U](sf: (T, U) => Boolean): BiPredicate[T, U]
    Annotations
    @inline()
  8. def asJavaBinaryOperator[T](sf: (T, T) => T): BinaryOperator[T]
    Annotations
    @inline()
  9. def asJavaBooleanSupplier(sf: () => Boolean): BooleanSupplier
    Annotations
    @inline()
  10. def asJavaConsumer[T](sf: (T) => Unit): Consumer[T]
    Annotations
    @inline()
  11. def asJavaDoubleBinaryOperator(sf: (Double, Double) => Double): DoubleBinaryOperator
    Annotations
    @inline()
  12. def asJavaDoubleConsumer(sf: (Double) => Unit): DoubleConsumer
    Annotations
    @inline()
  13. def asJavaDoubleFunction[R](sf: (Double) => R): DoubleFunction[R]
    Annotations
    @inline()
  14. def asJavaDoublePredicate(sf: (Double) => Boolean): DoublePredicate
    Annotations
    @inline()
  15. def asJavaDoubleSupplier(sf: () => Double): DoubleSupplier
    Annotations
    @inline()
  16. def asJavaDoubleToIntFunction(sf: (Double) => Int): DoubleToIntFunction
    Annotations
    @inline()
  17. def asJavaDoubleToLongFunction(sf: (Double) => Long): DoubleToLongFunction
    Annotations
    @inline()
  18. def asJavaDoubleUnaryOperator(sf: (Double) => Double): DoubleUnaryOperator
    Annotations
    @inline()
  19. def asJavaFunction[T, R](sf: (T) => R): java.util.function.Function[T, R]
    Annotations
    @inline()
  20. def asJavaIntBinaryOperator(sf: (Int, Int) => Int): IntBinaryOperator
    Annotations
    @inline()
  21. def asJavaIntConsumer(sf: (Int) => Unit): IntConsumer
    Annotations
    @inline()
  22. def asJavaIntFunction[R](sf: (Int) => R): IntFunction[R]
    Annotations
    @inline()
  23. def asJavaIntPredicate(sf: (Int) => Boolean): IntPredicate
    Annotations
    @inline()
  24. def asJavaIntSupplier(sf: () => Int): IntSupplier
    Annotations
    @inline()
  25. def asJavaIntToDoubleFunction(sf: (Int) => Double): IntToDoubleFunction
    Annotations
    @inline()
  26. def asJavaIntToLongFunction(sf: (Int) => Long): IntToLongFunction
    Annotations
    @inline()
  27. def asJavaIntUnaryOperator(sf: (Int) => Int): IntUnaryOperator
    Annotations
    @inline()
  28. def asJavaLongBinaryOperator(sf: (Long, Long) => Long): LongBinaryOperator
    Annotations
    @inline()
  29. def asJavaLongConsumer(sf: (Long) => Unit): LongConsumer
    Annotations
    @inline()
  30. def asJavaLongFunction[R](sf: (Long) => R): LongFunction[R]
    Annotations
    @inline()
  31. def asJavaLongPredicate(sf: (Long) => Boolean): LongPredicate
    Annotations
    @inline()
  32. def asJavaLongSupplier(sf: () => Long): LongSupplier
    Annotations
    @inline()
  33. def asJavaLongToDoubleFunction(sf: (Long) => Double): LongToDoubleFunction
    Annotations
    @inline()
  34. def asJavaLongToIntFunction(sf: (Long) => Int): LongToIntFunction
    Annotations
    @inline()
  35. def asJavaLongUnaryOperator(sf: (Long) => Long): LongUnaryOperator
    Annotations
    @inline()
  36. def asJavaObjDoubleConsumer[T](sf: (T, Double) => Unit): ObjDoubleConsumer[T]
    Annotations
    @inline()
  37. def asJavaObjIntConsumer[T](sf: (T, Int) => Unit): ObjIntConsumer[T]
    Annotations
    @inline()
  38. def asJavaObjLongConsumer[T](sf: (T, Long) => Unit): ObjLongConsumer[T]
    Annotations
    @inline()
  39. def asJavaPredicate[T](sf: (T) => Boolean): Predicate[T]
    Annotations
    @inline()
  40. def asJavaSupplier[T](sf: () => T): Supplier[T]
    Annotations
    @inline()
  41. def asJavaToDoubleBiFunction[T, U](sf: (T, U) => Double): ToDoubleBiFunction[T, U]
    Annotations
    @inline()
  42. def asJavaToDoubleFunction[T](sf: (T) => Double): ToDoubleFunction[T]
    Annotations
    @inline()
  43. def asJavaToIntBiFunction[T, U](sf: (T, U) => Int): ToIntBiFunction[T, U]
    Annotations
    @inline()
  44. def asJavaToIntFunction[T](sf: (T) => Int): ToIntFunction[T]
    Annotations
    @inline()
  45. def asJavaToLongBiFunction[T, U](sf: (T, U) => Long): ToLongBiFunction[T, U]
    Annotations
    @inline()
  46. def asJavaToLongFunction[T](sf: (T) => Long): ToLongFunction[T]
    Annotations
    @inline()
  47. def asJavaUnaryOperator[T](sf: (T) => T): UnaryOperator[T]
    Annotations
    @inline()
  48. def asScalaFromBiConsumer[T, U](jf: BiConsumer[T, U]): (T, U) => Unit
    Annotations
    @inline()
  49. def asScalaFromBiFunction[T, U, R](jf: BiFunction[T, U, R]): (T, U) => R
    Annotations
    @inline()
  50. def asScalaFromBiPredicate[T, U](jf: BiPredicate[T, U]): (T, U) => Boolean
    Annotations
    @inline()
  51. def asScalaFromBinaryOperator[T](jf: BinaryOperator[T]): (T, T) => T
    Annotations
    @inline()
  52. def asScalaFromBooleanSupplier(jf: BooleanSupplier): () => Boolean
    Annotations
    @inline()
  53. def asScalaFromConsumer[T](jf: Consumer[T]): (T) => Unit
    Annotations
    @inline()
  54. def asScalaFromDoubleBinaryOperator(jf: DoubleBinaryOperator): (Double, Double) => Double
    Annotations
    @inline()
  55. def asScalaFromDoubleConsumer(jf: DoubleConsumer): (Double) => Unit
    Annotations
    @inline()
  56. def asScalaFromDoubleFunction[R](jf: DoubleFunction[R]): (Double) => R
    Annotations
    @inline()
  57. def asScalaFromDoublePredicate(jf: DoublePredicate): (Double) => Boolean
    Annotations
    @inline()
  58. def asScalaFromDoubleSupplier(jf: DoubleSupplier): () => Double
    Annotations
    @inline()
  59. def asScalaFromDoubleToIntFunction(jf: DoubleToIntFunction): (Double) => Int
    Annotations
    @inline()
  60. def asScalaFromDoubleToLongFunction(jf: DoubleToLongFunction): (Double) => Long
    Annotations
    @inline()
  61. def asScalaFromDoubleUnaryOperator(jf: DoubleUnaryOperator): (Double) => Double
    Annotations
    @inline()
  62. def asScalaFromFunction[T, R](jf: java.util.function.Function[T, R]): (T) => R
    Annotations
    @inline()
  63. def asScalaFromIntBinaryOperator(jf: IntBinaryOperator): (Int, Int) => Int
    Annotations
    @inline()
  64. def asScalaFromIntConsumer(jf: IntConsumer): (Int) => Unit
    Annotations
    @inline()
  65. def asScalaFromIntFunction[R](jf: IntFunction[R]): (Int) => R
    Annotations
    @inline()
  66. def asScalaFromIntPredicate(jf: IntPredicate): (Int) => Boolean
    Annotations
    @inline()
  67. def asScalaFromIntSupplier(jf: IntSupplier): () => Int
    Annotations
    @inline()
  68. def asScalaFromIntToDoubleFunction(jf: IntToDoubleFunction): (Int) => Double
    Annotations
    @inline()
  69. def asScalaFromIntToLongFunction(jf: IntToLongFunction): (Int) => Long
    Annotations
    @inline()
  70. def asScalaFromIntUnaryOperator(jf: IntUnaryOperator): (Int) => Int
    Annotations
    @inline()
  71. def asScalaFromLongBinaryOperator(jf: LongBinaryOperator): (Long, Long) => Long
    Annotations
    @inline()
  72. def asScalaFromLongConsumer(jf: LongConsumer): (Long) => Unit
    Annotations
    @inline()
  73. def asScalaFromLongFunction[R](jf: LongFunction[R]): (Long) => R
    Annotations
    @inline()
  74. def asScalaFromLongPredicate(jf: LongPredicate): (Long) => Boolean
    Annotations
    @inline()
  75. def asScalaFromLongSupplier(jf: LongSupplier): () => Long
    Annotations
    @inline()
  76. def asScalaFromLongToDoubleFunction(jf: LongToDoubleFunction): (Long) => Double
    Annotations
    @inline()
  77. def asScalaFromLongToIntFunction(jf: LongToIntFunction): (Long) => Int
    Annotations
    @inline()
  78. def asScalaFromLongUnaryOperator(jf: LongUnaryOperator): (Long) => Long
    Annotations
    @inline()
  79. def asScalaFromObjDoubleConsumer[T](jf: ObjDoubleConsumer[T]): (T, Double) => Unit
    Annotations
    @inline()
  80. def asScalaFromObjIntConsumer[T](jf: ObjIntConsumer[T]): (T, Int) => Unit
    Annotations
    @inline()
  81. def asScalaFromObjLongConsumer[T](jf: ObjLongConsumer[T]): (T, Long) => Unit
    Annotations
    @inline()
  82. def asScalaFromPredicate[T](jf: Predicate[T]): (T) => Boolean
    Annotations
    @inline()
  83. def asScalaFromSupplier[T](jf: Supplier[T]): () => T
    Annotations
    @inline()
  84. def asScalaFromToDoubleBiFunction[T, U](jf: ToDoubleBiFunction[T, U]): (T, U) => Double
    Annotations
    @inline()
  85. def asScalaFromToDoubleFunction[T](jf: ToDoubleFunction[T]): (T) => Double
    Annotations
    @inline()
  86. def asScalaFromToIntBiFunction[T, U](jf: ToIntBiFunction[T, U]): (T, U) => Int
    Annotations
    @inline()
  87. def asScalaFromToIntFunction[T](jf: ToIntFunction[T]): (T) => Int
    Annotations
    @inline()
  88. def asScalaFromToLongBiFunction[T, U](jf: ToLongBiFunction[T, U]): (T, U) => Long
    Annotations
    @inline()
  89. def asScalaFromToLongFunction[T](jf: ToLongFunction[T]): (T) => Long
    Annotations
    @inline()
  90. def asScalaFromUnaryOperator[T](jf: UnaryOperator[T]): (T) => T
    Annotations
    @inline()
  91. def clone(): AnyRef

    Create a copy of the receiver object.

    Create a copy of the receiver object.

    The default implementation of the clone method is platform dependent.

    returns

    a copy of the receiver object.

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
    Note

    not specified by SLS as a member of AnyRef

  92. final def eq(arg0: AnyRef): Boolean

    Tests whether the argument (that) is a reference to the receiver object (this).

    Tests whether the argument (that) is a reference to the receiver object (this).

    The eq method implements an equivalence relation on non-null instances of AnyRef, and has three additional properties:

    • It is consistent: for any non-null instances x and y of type AnyRef, multiple invocations of x.eq(y) consistently returns true or consistently returns false.
    • For any non-null instance x of type AnyRef, x.eq(null) and null.eq(x) returns false.
    • null.eq(null) returns true.

    When overriding the equals or hashCode methods, it is important to ensure that their behavior is consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).

    returns

    true if the argument is a reference to the receiver object; false otherwise.

    Definition Classes
    AnyRef
  93. def equals(arg0: Any): Boolean

    The equality method for reference types.

    The equality method for reference types. Default implementation delegates to eq.

    See also equals in scala.Any.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    Definition Classes
    AnyRef → Any
  94. def finalize(): Unit

    Called by the garbage collector on the receiver object when there are no more references to the object.

    Called by the garbage collector on the receiver object when there are no more references to the object.

    The details of when and if the finalize method is invoked, as well as the interaction between finalize and non-local returns and exceptions, are all platform dependent.

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
    Note

    not specified by SLS as a member of AnyRef

  95. final def getClass(): Class[_]

    Returns the runtime class representation of the object.

    Returns the runtime class representation of the object.

    returns

    a class object corresponding to the runtime type of the receiver.

    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  96. def hashCode(): Int

    The hashCode method for reference types.

    The hashCode method for reference types. See hashCode in scala.Any.

    returns

    the hash code value for this object.

    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  97. final def isInstanceOf[T0]: Boolean

    Test whether the dynamic type of the receiver object is T0.

    Test whether the dynamic type of the receiver object is T0.

    Note that the result of the test is modulo Scala's erasure semantics. Therefore the expression 1.isInstanceOf[String] will return false, while the expression List(1).isInstanceOf[List[String]] will return true. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the specified type.

    returns

    true if the receiver object is an instance of erasure of type T0; false otherwise.

    Definition Classes
    Any
  98. final def ne(arg0: AnyRef): Boolean

    Equivalent to !(this eq that).

    Equivalent to !(this eq that).

    returns

    true if the argument is not a reference to the receiver object; false otherwise.

    Definition Classes
    AnyRef
  99. final def notify(): Unit

    Wakes up a single thread that is waiting on the receiver object's monitor.

    Wakes up a single thread that is waiting on the receiver object's monitor.

    Definition Classes
    AnyRef
    Annotations
    @native()
    Note

    not specified by SLS as a member of AnyRef

  100. final def notifyAll(): Unit

    Wakes up all threads that are waiting on the receiver object's monitor.

    Wakes up all threads that are waiting on the receiver object's monitor.

    Definition Classes
    AnyRef
    Annotations
    @native()
    Note

    not specified by SLS as a member of AnyRef

  101. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  102. def toString(): String

    Creates a String representation of this object.

    Creates a String representation of this object. The default representation is platform dependent. On the java platform it is the concatenation of the class name, "@", and the object's hashcode in hexadecimal.

    returns

    a String representation of the object.

    Definition Classes
    AnyRef → Any
  103. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  104. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  105. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  106. object Ops extends Priority0FunctionExtensions

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

Inherited from AnyRef

Inherited from Any

Ungrouped