I have a question on Java Syntax on lambda expressions and the java.util.function.Function Object. Also probably Spring Dependency Injection. It is an idiom that I don't know and I hope somebody can explain it to me. I know (probably only the basics) about that idiom of generic@FunctionalInterface(s) and "implementations" through lambda expressions. This use-case seems similar, but still different.
In the example, the Function<T,R>-Object is the Type of a parameter of a method of a configuration class with a parameter name. The argument is the lambda expression config -> tokenStore.
But please look at the information provided below. Here are my questions.
- What config is passed as the argument? There is no "config" symbol there. So I guess it is injected by the Spring IoC Container.
- And what it obviously returns is the symbol
tokenStorethat is bound to anorg.axonframework.eventhandling.tokenstore.TokenStoreInstance created by theJpaTokenStore#buildmethod. There is no connection to theconfigargument. Or is there? - To sum it up: Just "Why?" Why are you passing a lambda expression where there is no obvious (to me) connection between the argument and the return value and why are you passing a Function-placeholder to an Interface-method - how do you call it... the head of the method? Ultimately: What is that doing because to someone like me who obviously doesn't know the idiom it looks like the answer is: nothing ?
So, there is this example on how to configure a TokenStore from the Axon Framework and I would like to understand how it works:
public class AxonConfig {
// ...
public void registerTokenStore(EventProcessingConfigurer processingConfigurer) {
TokenStore tokenStore = JpaTokenStore.builder()
// …
.build();
processingConfigurer.registerTokenStore(config -> tokenStore);
}
}
source: https://docs.axoniq.io/reference-guide/axon-framework/events/event-processors/streaming#token-store
And here is the source code for the EventProcessingConfigurer#registerTokenStore (GitHub) method.
public interface EventProcessingConfigurer {
// ...
EventProcessingConfigurer registerTokenStore(Function<Configuration, TokenStore> tokenStore);
// ...
}
btw: can I pass in an argument for the code block to tell the forum software which language it is?
Thanks vonSpotz