Why and for what the function main
is written in the following way:
fun main(args: Array<String>) {
println("Hello, World!")
}
Why and for what the function main
is written in the following way:
fun main(args: Array<String>) {
println("Hello, World!")
}
Why?
By convention the start point of a program in Kotlin is a function with a signature as main(args: Array<String>)
, where args
represents the command line arguments passed to the program.
What for?
To allow arguments to be passed from the command line. This is achieved using the basic data types such as Strings and Arrays
If you want to try the function main
sending parameter you can access this link:
It is also important to note that from Kotlin 1.3 you can define the function main
without parameters ( Parameterless main ) if you do not require this behavior in the following way:
fun main() {
println("Hello, world!")
}
Finally, the following links may be of interest: