Class FunctionalInterfaceLogic


  • public final class FunctionalInterfaceLogic
    extends java.lang.Object
    Author:
    Federico Tomassetti
    • Method Detail

      • getFunctionalMethod

        public static java.util.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:
        Issue #3625
      • isFunctionalInterfaceType

        public static boolean isFunctionalInterfaceType​(ResolvedType type)