Alex
01/06/2021, 1:30 PMregistry.addConverter(
object : Converter<String, IaaSProvider> {
override fun convert(source: String): IaaSProvider = IaaSProvider.fromString(source)
}
)
Converter is a SAM interface, So technically it would be possible to do something like this:
registry.addConverter { source -> IaaSProvider.fromString(source) }
But how would I define generics in this lambda?Javier
01/06/2021, 1:38 PMAlex
01/06/2021, 2:00 PMvoid addConverter(Converter<?, ?> converter);
@FunctionalInterface
public interface Converter<S, T> {
/**
* Convert the source object of type {@code S} to target type {@code T}.
* @param source the source object to convert, which must be an instance of {@code S} (never {@code null})
* @return the converted object, which must be an instance of {@code T} (potentially {@code null})
* @throws IllegalArgumentException if the source cannot be converted to the desired target type
*/
@Nullable
T convert(S source);
}
Javier
01/06/2021, 2:10 PMAlex
01/06/2021, 2:17 PMfun <S, T> FormatterRegistry.addConverter(converter: Converter<S, T>) = addConverter(converter)