Sobes.tech
Junior

What functional interfaces do you know?

sobes.tech AI

Answer from AI

  • Predicate<T>: Accepts an argument of type T and returns a boolean value. Often used for filtering elements.
  • Consumer<T>: Accepts an argument of type T and returns nothing. Used for performing actions on elements.
  • Supplier<T>: Takes no arguments and returns a value of type T. Used for generating values.
  • Function<T, R>: Accepts an argument of type T and returns a value of type R. Used for transforming values.
  • UnaryOperator<T>: Extends Function<T, T>, accepts an argument of type T and returns a value of the same type.
  • BinaryOperator<T>: Extends BiFunction<T, T, T>, accepts two arguments of type T and returns a value of the same type. Often used in reduction operations.
  • BiPredicate<T, U>: Accepts two arguments of types T and U, returns a boolean value.
  • BiConsumer<T, U>: Accepts two arguments of types T and U, returns nothing.
  • BiFunction<T, U, R>: Accepts two arguments of types T and U, returns a value of type R.

Additionally, there are specialized functional interfaces for primitive types (IntPredicate, LongSupplier, DoubleConsumer, etc.) to avoid auto-boxing/unboxing, as well as interfaces with a return type of void (Runnable).