Doesn't this take away the feature of having multiple main entry points in java which can be called as and when required.
For now, just remember that main function is a mandatory function which is the entry point of every Kotlin program. The signature of main function is: fun main(args : Array<String>) { ... .. ... } println("Hello, World!")
Kotlin does not infer return types for functions with block bodies because such functions may have complex control flow in the body, and the return type will be non-obvious to the reader (and sometimes even for the compiler).
'Visible' refers to 'accessible'. And public makes it accessible from anywhere. open allows inheritance of a class.
In Kotlin, a function which can accept a function as parameter or can return a function is called Higher-Order function. Instead of Integer, String or Array as a parameter to function, we will pass anonymous function or lambdas. Frequently, lambdas are passed as parameter in Kotlin functions for the convenience.
In addition to Sergey Mashkov's comment: you can put a main
inside an object and mark it @JvmStatic
:
object Main {
@JvmStatic
fun main(args: Array<String>) {
println("Hello, world!")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With