```@Configuration class MetricsConfig { @Bean ...
# getting-started
k
Copy code
@Configuration
class MetricsConfig {
   @Bean
   fun commonTags(): MeterRegistryCustomizer<MeterRegistry> = { registry ->    
      registry.config().commonTags("kenneth", "kenneth2")
   }
}
Gives:
Copy code
Inferred type is a function type, but a non-function type MeterRegistryCustomizer<MeterRegistry> was expected. Use either '= ...' or '{ ... }', but not both
d
you’re mixing lambda syntax with a function declaration. You should not be declaring “commonTags” as a fun or include the parentheses after commonTags.
but it seems like there is more going on here than that. What is MeterRegistryCustomizer? It doesn’t look like a function type (for example (Registry) -> Unit) so storing a lambda in that variable won’t work either
k
Copy code
@FunctionalInterface
public interface MeterRegistryCustomizer<T extends MeterRegistry> {
	/**
	 * Customize the given {@code registry}.
	 * @param registry the registry to customize
	 */
	void customize(T registry);
}
a
@Kenneth
commonTags
needs to return a
MeterRegistryCustomizer<MeterRegistry>
?
k
@Andreas Sinz correct
a
@Kenneth then try this one
Copy code
fun 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 type
k
Ah, I see. The code seems to work great, thanks! I guess I need to read up on lamdas, didn't know you could replace the : with =. Cool!
a
you can read about it here: https://kotlinlang.org/docs/reference/functions.html#single-expression-functions You can even omit the return type when you use the
=
syntax, because kotlin can infer it in most of the cases 😄
k
Sweet 🙂