Class ClassInstanceLoader

java.lang.Object
dev.langchain4j.classinstance.ClassInstanceLoader

public final class ClassInstanceLoader extends Object
Utility class for creating and retrieving instances of specified class types. This class provides a mechanism to delegate instance creation to a factory, if available, or fallback to direct instantiation using the no-argument constructor.

This is useful in scenarios where dependency injection frameworks or other managed object factories might need to be leveraged for object creation.

  • Method Details

    • getClassInstance

      public static <T> T getClassInstance(Class<T> clazz)
      Retrieves an instance of the specified class type. This method first attempts to obtain the instance through a ClassInstanceFactory, if available. If no factory is present, it creates a new instance of the class using its no-argument constructor.
      Type Parameters:
      T - the type of the class
      Parameters:
      clazz - the class object representing the type whose instance is to be created
      Returns:
      an instance of the specified class type