Reputation: 1677
I am new to Kotlin development and I have created a separate Kotlin class in Android Studio as below :
class MainClass{
fun main(args: Array<String>) {
println("Hello World");
}
}
But, How can I run this kotlin class, and where the output will be generated.
Upvotes: 4
Views: 1639
Reputation: 802
Use this code, You will see a run icon near function.
class Test {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println("Hello test!")
}
}
}
Upvotes: 0
Reputation: 66
your main function has to be a top-level function. Try this:
fun main(args: Array<String>) {
println("Hello World");
}
In order to run it, just click on green the icon next to the function name in AS.
Upvotes: 5