To add a bit more context, If you compare this with the entry point in a Java class, you could see a
public
and
static
keyword as part of the main method signature. Your second example example get translated to this because of that companion object and static annotation, and that's why it worked.
In case of Kotlin, the entry point is a
top level function (without enclosing that inside a class). And like
@Klitos Kyriacou said, when you wrap it inside a class, it becomes an ordinary instance method.
Also,
runApplication<ApiApplication>(*args)
is just a Kotlin idiomatic alternative to
SpringApplication.run(ApiApplication::class.java, *args)