Kenneth
02/12/2018, 10:32 PM@Configuration
class MetricsConfig {
@Bean
fun commonTags(): MeterRegistryCustomizer<MeterRegistry> = { registry ->
registry.config().commonTags("kenneth", "kenneth2")
}
}
Gives:
Inferred type is a function type, but a non-function type MeterRegistryCustomizer<MeterRegistry> was expected. Use either '= ...' or '{ ... }', but not both
dknapp
02/12/2018, 10:36 PMdknapp
02/12/2018, 10:38 PMKenneth
02/12/2018, 10:38 PM@FunctionalInterface
public interface MeterRegistryCustomizer<T extends MeterRegistry> {
/**
* Customize the given {@code registry}.
* @param registry the registry to customize
*/
void customize(T registry);
}
Andreas Sinz
02/13/2018, 8:42 AMcommonTags
needs to return a MeterRegistryCustomizer<MeterRegistry>
?Kenneth
02/13/2018, 6:13 PMAndreas Sinz
02/13/2018, 6:15 PMfun commonTags() = MeterRegistryCustomizer<MeterRegistry> { registry ->
registry.config().commonTags("kenneth", "kenneth2")
}
Sometimes you need to tell the compiler which FunctionalInterface
your lambda "implements". And because we already told the compiler what the type of the lambda will be, we don't need to specify it again as the method return typeKenneth
02/13/2018, 6:23 PMAndreas Sinz
02/13/2018, 6:26 PM=
syntax, because kotlin can infer it in most of the cases 😄Kenneth
02/13/2018, 6:49 PM