private static Constructor<?> getConstructor(@NotNull RemoteCall call, @NotNull Class<?> targetClass, Object[] transformedArgs) {
    int argCount = call.getArgs().length;
    List<Constructor<?>> availableConstructors = Arrays.stream(targetClass.getConstructors()).toList();
    List<Constructor<?>> constructors = availableConstructors.stream()
      .filter(x -> x.getParameterCount() == argCount)
      .toList();

    if (constructors.isEmpty()) {
      throw new IllegalStateException(
        String.format("No constructor with parameter count %s in class %s. Available constructors: %n%s",
                      argCount, call.getClassName(),
                      availableConstructors.stream().map(it -> it.toString())
                        .collect(Collectors.joining(" - " + System.lineSeparator()))
        ));
    }

    if (constructors.size() > 1) {
      List<@Nullable Class<?>> argumentTypes = getArgumentTypes(transformedArgs);
      // take into account argument types
      for (Constructor<?> constructor : constructors) {
        if (areTypesCompatible(constructor.getParameterTypes(), argumentTypes)) {
          return constructor;
        }
      }
    }

    return constructors.get(0);
  }
private static Constructor<?> getConstructor(@NotNull RemoteCall call, @NotNull Class<?> targetClass, Object[] transformedArgs)