0

About kotlin

Why do we use args:Array<String> inside fun main()

29th Jun 2020, 5:01 AM
Shivendra Gupta
3 Respostas
+ 4
Because of this question, I added this lesson to my series on Kotlin. https://www.sololearn.com/post/454740
1st Jul 2020, 11:01 PM
John Wells
John Wells - avatar
+ 3
Kotlin version 1.3 removes the need to have the parameter. It's purpose is to access the command line arguments your program was run with. Say you write a simple program that takes any number and state if it was even or odd. You could test args size for greater than 1. If it fails, read the number. Otherwise, the number is args[1]. The program name is args[0]. Running like: test 5, would process 5, while: test, would read a number. Each space separated string off the command fills in the various args elements so args[0] would be test.
29th Jun 2020, 4:46 PM
John Wells
John Wells - avatar
+ 1
This argument used to show the main method inside class like class m{ companion object { @JvmStatic fun main(arg: Array<String>){ //ur code goes here } } } But if u are using only function like fun main(){} outside the class or object it is usless to put arg: Array<String>
29th Jun 2020, 7:11 AM
Ananiya Jemberu
Ananiya Jemberu - avatar