public static void main in Kotlin












1















In Java, especially in Android studio, every time that I want to run or test some Java source code quickly, I will create public static void main (shortkey: psvm + tab) and the IDE will show "Play" button to run it immediately.



enter image description here



Do we have some kind of psvm in Kotlin - an entry point or something in order to run or test anything that quickly? Did try with this function but it wasn't working. (Even try with @JvmStatic). Can we config somewhere in Android studio?



fun main(args: Array<String>) {

}









share|improve this question























  • I think you need to put it inside a companion object with the @JvmStatic annotation.

    – TheWanderer
    Dec 31 '18 at 16:33











  • It works. Thank you @TheWanderer.

    – nhp
    Dec 31 '18 at 16:35
















1















In Java, especially in Android studio, every time that I want to run or test some Java source code quickly, I will create public static void main (shortkey: psvm + tab) and the IDE will show "Play" button to run it immediately.



enter image description here



Do we have some kind of psvm in Kotlin - an entry point or something in order to run or test anything that quickly? Did try with this function but it wasn't working. (Even try with @JvmStatic). Can we config somewhere in Android studio?



fun main(args: Array<String>) {

}









share|improve this question























  • I think you need to put it inside a companion object with the @JvmStatic annotation.

    – TheWanderer
    Dec 31 '18 at 16:33











  • It works. Thank you @TheWanderer.

    – nhp
    Dec 31 '18 at 16:35














1












1








1








In Java, especially in Android studio, every time that I want to run or test some Java source code quickly, I will create public static void main (shortkey: psvm + tab) and the IDE will show "Play" button to run it immediately.



enter image description here



Do we have some kind of psvm in Kotlin - an entry point or something in order to run or test anything that quickly? Did try with this function but it wasn't working. (Even try with @JvmStatic). Can we config somewhere in Android studio?



fun main(args: Array<String>) {

}









share|improve this question














In Java, especially in Android studio, every time that I want to run or test some Java source code quickly, I will create public static void main (shortkey: psvm + tab) and the IDE will show "Play" button to run it immediately.



enter image description here



Do we have some kind of psvm in Kotlin - an entry point or something in order to run or test anything that quickly? Did try with this function but it wasn't working. (Even try with @JvmStatic). Can we config somewhere in Android studio?



fun main(args: Array<String>) {

}






java android android-studio kotlin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 31 '18 at 16:32









nhpnhp

1,900414




1,900414













  • I think you need to put it inside a companion object with the @JvmStatic annotation.

    – TheWanderer
    Dec 31 '18 at 16:33











  • It works. Thank you @TheWanderer.

    – nhp
    Dec 31 '18 at 16:35



















  • I think you need to put it inside a companion object with the @JvmStatic annotation.

    – TheWanderer
    Dec 31 '18 at 16:33











  • It works. Thank you @TheWanderer.

    – nhp
    Dec 31 '18 at 16:35

















I think you need to put it inside a companion object with the @JvmStatic annotation.

– TheWanderer
Dec 31 '18 at 16:33





I think you need to put it inside a companion object with the @JvmStatic annotation.

– TheWanderer
Dec 31 '18 at 16:33













It works. Thank you @TheWanderer.

– nhp
Dec 31 '18 at 16:35





It works. Thank you @TheWanderer.

– nhp
Dec 31 '18 at 16:35












3 Answers
3






active

oldest

votes


















2














You can just put the main function outside of any class.



In anyFile.kt do:



package foo

fun main(args: Array<String>) {

}


enter image description here



Either main + tab or psvm + tab work if you have your cursor outside of a class.






share|improve this answer


























  • Outside of any class is the point. Thank you

    – nhp
    Dec 31 '18 at 16:59



















3














Put it inside a companion object with the @JvmStatic annotation:



class Test {
companion object {
@JvmStatic
fun main(args: Array<String>) {}
}
}





share|improve this answer































    1














    Yes, shortkey: main + tab in any kotlin file



    It will generate



    fun main(args: Array<String>) {

    }





    share|improve this answer


























    • This does not work inside of a class. (And that was the confusion)

      – leonardkraemer
      Dec 31 '18 at 16:53











    • @leonardkraemer, The question was about how to generate main function quickly

      – Omar Mainegra
      Dec 31 '18 at 16:55











    • psvm + tab works as well, just not inside a class.

      – leonardkraemer
      Dec 31 '18 at 16:56











    • Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.

      – nhp
      Dec 31 '18 at 17:01











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989520%2fpublic-static-void-main-in-kotlin%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You can just put the main function outside of any class.



    In anyFile.kt do:



    package foo

    fun main(args: Array<String>) {

    }


    enter image description here



    Either main + tab or psvm + tab work if you have your cursor outside of a class.






    share|improve this answer


























    • Outside of any class is the point. Thank you

      – nhp
      Dec 31 '18 at 16:59
















    2














    You can just put the main function outside of any class.



    In anyFile.kt do:



    package foo

    fun main(args: Array<String>) {

    }


    enter image description here



    Either main + tab or psvm + tab work if you have your cursor outside of a class.






    share|improve this answer


























    • Outside of any class is the point. Thank you

      – nhp
      Dec 31 '18 at 16:59














    2












    2








    2







    You can just put the main function outside of any class.



    In anyFile.kt do:



    package foo

    fun main(args: Array<String>) {

    }


    enter image description here



    Either main + tab or psvm + tab work if you have your cursor outside of a class.






    share|improve this answer















    You can just put the main function outside of any class.



    In anyFile.kt do:



    package foo

    fun main(args: Array<String>) {

    }


    enter image description here



    Either main + tab or psvm + tab work if you have your cursor outside of a class.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 31 '18 at 16:59

























    answered Dec 31 '18 at 16:41









    leonardkraemerleonardkraemer

    3,44111532




    3,44111532













    • Outside of any class is the point. Thank you

      – nhp
      Dec 31 '18 at 16:59



















    • Outside of any class is the point. Thank you

      – nhp
      Dec 31 '18 at 16:59

















    Outside of any class is the point. Thank you

    – nhp
    Dec 31 '18 at 16:59





    Outside of any class is the point. Thank you

    – nhp
    Dec 31 '18 at 16:59













    3














    Put it inside a companion object with the @JvmStatic annotation:



    class Test {
    companion object {
    @JvmStatic
    fun main(args: Array<String>) {}
    }
    }





    share|improve this answer




























      3














      Put it inside a companion object with the @JvmStatic annotation:



      class Test {
      companion object {
      @JvmStatic
      fun main(args: Array<String>) {}
      }
      }





      share|improve this answer


























        3












        3








        3







        Put it inside a companion object with the @JvmStatic annotation:



        class Test {
        companion object {
        @JvmStatic
        fun main(args: Array<String>) {}
        }
        }





        share|improve this answer













        Put it inside a companion object with the @JvmStatic annotation:



        class Test {
        companion object {
        @JvmStatic
        fun main(args: Array<String>) {}
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 16:40









        TheWandererTheWanderer

        7,44521129




        7,44521129























            1














            Yes, shortkey: main + tab in any kotlin file



            It will generate



            fun main(args: Array<String>) {

            }





            share|improve this answer


























            • This does not work inside of a class. (And that was the confusion)

              – leonardkraemer
              Dec 31 '18 at 16:53











            • @leonardkraemer, The question was about how to generate main function quickly

              – Omar Mainegra
              Dec 31 '18 at 16:55











            • psvm + tab works as well, just not inside a class.

              – leonardkraemer
              Dec 31 '18 at 16:56











            • Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.

              – nhp
              Dec 31 '18 at 17:01
















            1














            Yes, shortkey: main + tab in any kotlin file



            It will generate



            fun main(args: Array<String>) {

            }





            share|improve this answer


























            • This does not work inside of a class. (And that was the confusion)

              – leonardkraemer
              Dec 31 '18 at 16:53











            • @leonardkraemer, The question was about how to generate main function quickly

              – Omar Mainegra
              Dec 31 '18 at 16:55











            • psvm + tab works as well, just not inside a class.

              – leonardkraemer
              Dec 31 '18 at 16:56











            • Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.

              – nhp
              Dec 31 '18 at 17:01














            1












            1








            1







            Yes, shortkey: main + tab in any kotlin file



            It will generate



            fun main(args: Array<String>) {

            }





            share|improve this answer















            Yes, shortkey: main + tab in any kotlin file



            It will generate



            fun main(args: Array<String>) {

            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 31 '18 at 16:55

























            answered Dec 31 '18 at 16:47









            Omar MainegraOmar Mainegra

            2,3871020




            2,3871020













            • This does not work inside of a class. (And that was the confusion)

              – leonardkraemer
              Dec 31 '18 at 16:53











            • @leonardkraemer, The question was about how to generate main function quickly

              – Omar Mainegra
              Dec 31 '18 at 16:55











            • psvm + tab works as well, just not inside a class.

              – leonardkraemer
              Dec 31 '18 at 16:56











            • Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.

              – nhp
              Dec 31 '18 at 17:01



















            • This does not work inside of a class. (And that was the confusion)

              – leonardkraemer
              Dec 31 '18 at 16:53











            • @leonardkraemer, The question was about how to generate main function quickly

              – Omar Mainegra
              Dec 31 '18 at 16:55











            • psvm + tab works as well, just not inside a class.

              – leonardkraemer
              Dec 31 '18 at 16:56











            • Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.

              – nhp
              Dec 31 '18 at 17:01

















            This does not work inside of a class. (And that was the confusion)

            – leonardkraemer
            Dec 31 '18 at 16:53





            This does not work inside of a class. (And that was the confusion)

            – leonardkraemer
            Dec 31 '18 at 16:53













            @leonardkraemer, The question was about how to generate main function quickly

            – Omar Mainegra
            Dec 31 '18 at 16:55





            @leonardkraemer, The question was about how to generate main function quickly

            – Omar Mainegra
            Dec 31 '18 at 16:55













            psvm + tab works as well, just not inside a class.

            – leonardkraemer
            Dec 31 '18 at 16:56





            psvm + tab works as well, just not inside a class.

            – leonardkraemer
            Dec 31 '18 at 16:56













            Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.

            – nhp
            Dec 31 '18 at 17:01





            Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.

            – nhp
            Dec 31 '18 at 17:01


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989520%2fpublic-static-void-main-in-kotlin%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas