Class FunctionalInterfaceLoggingNameResolver

java.lang.Object
dk.cloudcreate.essentials.shared.reflection.FunctionalInterfaceLoggingNameResolver

public final class FunctionalInterfaceLoggingNameResolver extends Object
Utility for resolving human-readable, meaningful names from functional interface implementations - also supports normal classes.

This class attempts to provide clear and informative names from lambda expressions and method references for logging and debugging purposes, trying to avoid default obscure names like $$Lambda$123.

It uses several strategies to extract names, in order of preference:

  1. Functional interface information / class name
  2. Stack trace analysis

Implementation notes:

  • Results are cached internally for performance
  • Handles Java security restrictions gracefully
  • Thread-safe implementation
  • Method Details

    • resolveLoggingName

      public static String resolveLoggingName(Object handler)
      Resolves a logging‐friendly name for the provided functional interface implementation - also supports normal classes.

      If the implementation is a lambda expression, this method attempts to extract the underlying implementation class and method via reflection. Otherwise, it falls back to the class's simple name. The result is cached per implementation class.

      Parameters:
      handler - the functional interface implementation or class instance
      Returns:
      a logging‐friendly name for diagnostic purposes
      Throws:
      IllegalArgumentException - if the handler is null
    • extractClassNameFromLambda

      public static String extractClassNameFromLambda(String lambdaString)