Class FunctionalInterfaceLogic

java.lang.Object
com.github.javaparser.resolution.logic.FunctionalInterfaceLogic

public final class FunctionalInterfaceLogic extends Object
Author:
Federico Tomassetti
  • Method Details

    • getFunctionalMethod

      public static Optional<MethodUsage> getFunctionalMethod(ResolvedType type)
      Get the functional method defined by the type, if any.

      Per JLS §9.8, a functional interface is always an interface, which is a reference type. Primitive types, array types, and void can therefore never be functional interfaces. Passing such a type returns Optional.empty() immediately without throwing an exception.

      Note: bounded type variables (<T extends Runnable>) and intersection types (Runnable & Serializable) are not handled here and also return Optional.empty(). Supporting those cases is a separate, more complex enhancement (see JLS §15.27.3).

      Parameters:
      type - the resolved type to inspect — may be any ResolvedType subclass
      Returns:
      the single abstract method of the functional interface, or empty if the type is not a functional interface or is not a reference type at all
      See Also:
    • getFunctionalMethod

      public static Optional<MethodUsage> getFunctionalMethod(ResolvedReferenceTypeDeclaration typeDeclaration)
      Get the functional method defined by the type, if any.
    • isFunctionalInterfaceType

      public static boolean isFunctionalInterfaceType(ResolvedType type)