Hi everyone. I notice that in Java you can use so...
# spring
a
Hi everyone. I notice that in Java you can use something like
Copy code
SpringApplication.from(xxxx::main).with(yyyy.class).run(args)
to copy the configuration of your main xxxx SpringBootApplication class and extend it with the configuration class yyyy.class Specifying xxxx::main in Kotlin don't want to resolve in Intellij, but for Java it works. The argument for the
.from
method is of type
ThrowingConsumer
which neither the Java main or the Kotlin main functions match, yet it works for Java, but not Kotlin. I guess the broader question is, can you get a function reference to
fun main(..)
and how do you use it?
1
j
Whats the type parameter for the ThrowingConsumer? https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/function/ThrowingConsumer.html I'm guessing your problem is that your not consuming the args in your kotlin version of the main function
a
Copy code
public static SpringApplication.Augmented from(ThrowingConsumer<String[]> main) {
		Assert.notNull(main, "Main must not be null");
		return new Augmented(main, Collections.emptySet());
	}
that's the implementation of the method I'm trying to call.
and this is how I'm trying to call it:
Copy code
SpringApplication
        .from(Application::main)
        .with(TestApplication::class.java)
        .run(*args)
The above is in the main function of TestApplication
Now, Application does compile to ApplicationKt in bytecode with a static main method. Can't get intellij to resolve ApplicationKt::main either though.
Ok, I might have been able to get around it by using an import alias.
worked