Since Kotlin 1.3 the `fun main(args: Array<String>...
# language-proposals
v
Since Kotlin 1.3 the
fun main(args: Array<String>)
function is permited to be simplified as
fun main()
(when the entry arguments are not used). My suggest is that, when the arguments of the entry
main
function ARE used, the IDE/Compiler may accept just
fun main(args)
, assuming the type of
args
would be
Array<String>
.
14
r
I'm not a fan of this one. Currently, both forms of main are still valid function definitions, whereas
fun main(args)
isn't.
2
k
I would rather see this done like Cocoa+Swift, where there is no main method (instead, a main file) and if you want the arguments you call
CommandLine.arguments
https://developer.apple.com/documentation/swift/commandline/2294816-arguments
k
does that mean the CommandLine is a
private val commandLine: CommandLine
in the file?
r
@Ky Leggiero I'm actually not a fan of that one either. It would probably require a bigger / more invasive runtime wrapper. Not to mention it would have implications like what happens if I change the values of the array and some other function uses it elsewhere. Personally, I like it as it is.
1
k
@ki Usage is like:
Copy code
print(Int(CommandLine.arguments) == 42)
@Ruckus Not as far as I know. It's just a nicer syntax on top of what we're already doing. It can even be inlined if you're really concerned, but we're not exactly doing kernel code in Kotlin :P