harry.singh
02/21/2022, 5:22 PMmain
function private
in a kotlin file and it is still executable. How does JVM access the function if it is private
and make it executable?Rob Elliot
02/21/2022, 5:36 PMTools > Kotlin > Show Kotlin Bytecode
and then click the Decompile
button at the top of the bytecode and see what Kotlin generated.harry.singh
02/21/2022, 5:38 PMRob Elliot
02/21/2022, 5:38 PMpublic static void main
that calls your one, which is why yours being private doesn't matter.Klitos Kyriacou
02/21/2022, 5:38 PMprivate fun main(args: Array<String>)
work?fun main(args: Array<String>)
, fun main()
, or private fun main()
but not private fun main(args: Array<String>)
?Rob Elliot
02/21/2022, 5:46 PMargs: Array<String>
as an argument then it doesn't generate a synthetic main method at all, so it can't make it public, so that's why it doesn't work.private fun main(args: Array<String>) {
println("hi")
}
becomes
public final class MainKt {
private static final void main(String[] args) {
String var1 = "hi";
System.out.println(var1);
}
}
Klitos Kyriacou
02/21/2022, 5:51 PMJoffrey
02/21/2022, 5:53 PMmain
should be considered a feature or a bug to be honest 🤔harry.singh
02/21/2022, 5:53 PMJoffrey
02/21/2022, 5:54 PMprivate fun main()
without argumentsRob Elliot
02/21/2022, 5:55 PMJoffrey
02/21/2022, 5:57 PMKlitos Kyriacou
02/21/2022, 6:01 PM