Kotlin Creating the main function

Source: Internet
Author: User

When testing the Kotlin, we need a main function entry that is the same as the Java language, so be careful how you create it.

Right-click  

Select the File type when you create a new item here.

When you click OK, you create a. kt file that basically has nothing but a package xx.
Then enter main return, the final generated main function:

Fun Main (args:array<string>) {

}

After generating the main function, we can create the class directly in the current. kt file, which is a bit different from Java, where the main function of Java is written in class, and Kotlin's main function is written in class and can only be used as a regular method to tune Use. So our normal test should say this:

Fun Main (args:array<string>) {
    var demo1 = Demo1 ()
    demo1.testfun ("content")
}

class Demo1 {
    var name:string = "" Fun

    Testfun (name:string) {
        this.name = name
        println (this.name)
    }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.