Doubt about Kotlin language

0

Why and for what the function main is written in the following way:

fun main(args: Array<String>) {
    println("Hello, World!")
}
    
asked by Leonel Alfaro 27.10.2018 в 02:53
source

1 answer

2
  

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:

answered by 27.10.2018 / 08:41
source