Sobes.tech
Junior — Middle

Можешь перечислить ключевые характеристики функциональных интерфейсов в программировании?

sobes.tech AI

Answer from AI

Functional interfaces in Java are interfaces with exactly one abstract method, which allows them to be used as target types for lambda expressions and method references.

Key characteristics:

  • One abstract method (SAM - Single Abstract Method).
  • Can contain default methods with implementations.
  • Can contain static methods.
  • Annotated with @FunctionalInterface (not mandatory, but recommended for verification).
  • Enable writing more concise and expressive code using lambdas.

Example:

@FunctionalInterface
public interface Converter<F, T> {
    T convert(F from);
}

// Usage
Converter<String, Integer> stringToInteger = Integer::valueOf;
int number = stringToInteger.convert("123");