Created
June 5, 2017 09:19
-
-
Save ajoz/015e267881b563012af00b6c24633ac1 to your computer and use it in GitHub Desktop.
public static void main function in Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
// This will not work because its not a static method! | |
// You cannot annotate it with @JvmStatic (usable only | |
// in objects and companion objects) | |
// You have 4 options: | |
fun main(args: Array<String>) { | |
prinltn("This won't work as expected") | |
} | |
// this will clash with main above during compilation! | |
companion object { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
println("Option 1: companion object") | |
} | |
} | |
object Test { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
println("Option 2: internal object (inner static final class)") | |
} | |
} | |
} | |
object Test2 { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
println("Option 3: just an object") | |
} | |
} | |
fun main(args: Array<String>) { | |
println("Option 4: free floating function") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment