Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run single Kotlin class from Android Studio

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.

like image 799
Jaimin Modi Avatar asked Oct 20 '25 18:10

Jaimin Modi


1 Answers

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.

Check out this screenshot

like image 141
Luis Carino Avatar answered Oct 23 '25 09:10

Luis Carino