Is there any difference between empty block and UnitTry-with-resources in KotlinIn Kotlin, what is the idiomatic way to deal with nullable values, referencing or converting themKotlin - Property initialization using “by lazy” vs. “lateinit”Coding convention for empty functions that need to be overridden in KotlinUnion type between Any? and Unitwhat is `open` keyword for fields in Kotlin?Simplifying return from multiple nested blocks in KotlinWhat's the difference between HashMap and MutableMap in KotlinWhat is the difference between not-null checks in Kotlin?How and when does kotlin let run?

First Number to Contain Each Letter

Has Rey's new lightsaber been seen before in canon or legends?

How does Harry wear the invisibility cloak?

What is this red bug infesting some trees in southern Germany?

Does immunity to damage from nonmagical attacks negate a rogue's Sneak Attack damage?

Why do we need explainable AI?

Time to call the bluff

Confusion in understanding control system?

How does speed affect lift?

How to generate all 3×3 matrices with a,a,a,a,b,b,b,c,c?

Which is the best password hashing algorithm in .NET Core?

Spare the Dying during Rage Beyond Death

Punishment in pacifist society

Is it rude to ask my opponent to resign an online game when they have a lost endgame?

Can I sleep overnight at Stansted Airport

How to find better food in airports

'This one' as a pronoun

Tiny image scraper for xkcd.com

Planet that’s 90% water or more?

Does this bike use hydraulic brakes?

Case Studies and Real Problems for Teaching Optimization and Modelling

Why did the Joi advertisement trigger K?

How to anonymously report the Establishment Clause being broken?

Everyone for non livings



Is there any difference between empty block and Unit


Try-with-resources in KotlinIn Kotlin, what is the idiomatic way to deal with nullable values, referencing or converting themKotlin - Property initialization using “by lazy” vs. “lateinit”Coding convention for empty functions that need to be overridden in KotlinUnion type between Any? and Unitwhat is `open` keyword for fields in Kotlin?Simplifying return from multiple nested blocks in KotlinWhat's the difference between HashMap and MutableMap in KotlinWhat is the difference between not-null checks in Kotlin?How and when does kotlin let run?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Is there any difference between empty block and returning Unit?



for example, we should make empty block to method do nothing



void ThisMethodDoesNothing() 





In kotlin, we can write code above but this way



fun ThisMethodDoesNothing() = Unit





Please let me know if this is duplicated, thanks.










share|improve this question






























    0















    Is there any difference between empty block and returning Unit?



    for example, we should make empty block to method do nothing



    void ThisMethodDoesNothing() 





    In kotlin, we can write code above but this way



    fun ThisMethodDoesNothing() = Unit





    Please let me know if this is duplicated, thanks.










    share|improve this question


























      0












      0








      0








      Is there any difference between empty block and returning Unit?



      for example, we should make empty block to method do nothing



      void ThisMethodDoesNothing() 





      In kotlin, we can write code above but this way



      fun ThisMethodDoesNothing() = Unit





      Please let me know if this is duplicated, thanks.










      share|improve this question














      Is there any difference between empty block and returning Unit?



      for example, we should make empty block to method do nothing



      void ThisMethodDoesNothing() 





      In kotlin, we can write code above but this way



      fun ThisMethodDoesNothing() = Unit





      Please let me know if this is duplicated, thanks.







      kotlin






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 3:25









      SlaneRSlaneR

      4393 silver badges13 bronze badges




      4393 silver badges13 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          3
















          I figured that the two probably did the same thing, but I had no way to be sure. I really wanted to know. So I created a class to put each of these in (since Java must have a class around any code), changed the Kotlin version so that the attributes on the method were the same, and that gave me this:



          a.java



          public class a 
          public final void ThisMethodDoesNothing()



          b.kt



          class b 
          fun ThisMethodDoesNothing() = Unit



          Then I compiled each of these, and then decompiled them with javad -c, and got:



          > javap -c com.inlet.ifserver.a
          Compiled from "a.java"
          public class com.inlet.ifserver.a
          public com.inlet.ifserver.a();
          Code:
          0: aload_0
          1: invokespecial #1 // Method java/lang/Object."<init>":()V
          4: return

          public final void ThisMethodDoesNothing();
          Code:
          0: return


          > javap -c com.inlet.ifserver.b
          Compiled from "b.kt"
          public final class com.inlet.ifserver.b
          public final void ThisMethodDoesNothing();
          Code:
          0: return

          public com.inlet.ifserver.b();
          Code:
          0: aload_0
          1: invokespecial #11 // Method java/lang/Object."<init>":()V
          4: return



          So I think the answer is a resounding YES! Both do absolutely nothing.






          share|improve this answer
























            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%2f55389695%2fis-there-any-difference-between-empty-block-and-unit%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3
















            I figured that the two probably did the same thing, but I had no way to be sure. I really wanted to know. So I created a class to put each of these in (since Java must have a class around any code), changed the Kotlin version so that the attributes on the method were the same, and that gave me this:



            a.java



            public class a 
            public final void ThisMethodDoesNothing()



            b.kt



            class b 
            fun ThisMethodDoesNothing() = Unit



            Then I compiled each of these, and then decompiled them with javad -c, and got:



            > javap -c com.inlet.ifserver.a
            Compiled from "a.java"
            public class com.inlet.ifserver.a
            public com.inlet.ifserver.a();
            Code:
            0: aload_0
            1: invokespecial #1 // Method java/lang/Object."<init>":()V
            4: return

            public final void ThisMethodDoesNothing();
            Code:
            0: return


            > javap -c com.inlet.ifserver.b
            Compiled from "b.kt"
            public final class com.inlet.ifserver.b
            public final void ThisMethodDoesNothing();
            Code:
            0: return

            public com.inlet.ifserver.b();
            Code:
            0: aload_0
            1: invokespecial #11 // Method java/lang/Object."<init>":()V
            4: return



            So I think the answer is a resounding YES! Both do absolutely nothing.






            share|improve this answer





























              3
















              I figured that the two probably did the same thing, but I had no way to be sure. I really wanted to know. So I created a class to put each of these in (since Java must have a class around any code), changed the Kotlin version so that the attributes on the method were the same, and that gave me this:



              a.java



              public class a 
              public final void ThisMethodDoesNothing()



              b.kt



              class b 
              fun ThisMethodDoesNothing() = Unit



              Then I compiled each of these, and then decompiled them with javad -c, and got:



              > javap -c com.inlet.ifserver.a
              Compiled from "a.java"
              public class com.inlet.ifserver.a
              public com.inlet.ifserver.a();
              Code:
              0: aload_0
              1: invokespecial #1 // Method java/lang/Object."<init>":()V
              4: return

              public final void ThisMethodDoesNothing();
              Code:
              0: return


              > javap -c com.inlet.ifserver.b
              Compiled from "b.kt"
              public final class com.inlet.ifserver.b
              public final void ThisMethodDoesNothing();
              Code:
              0: return

              public com.inlet.ifserver.b();
              Code:
              0: aload_0
              1: invokespecial #11 // Method java/lang/Object."<init>":()V
              4: return



              So I think the answer is a resounding YES! Both do absolutely nothing.






              share|improve this answer



























                3














                3










                3









                I figured that the two probably did the same thing, but I had no way to be sure. I really wanted to know. So I created a class to put each of these in (since Java must have a class around any code), changed the Kotlin version so that the attributes on the method were the same, and that gave me this:



                a.java



                public class a 
                public final void ThisMethodDoesNothing()



                b.kt



                class b 
                fun ThisMethodDoesNothing() = Unit



                Then I compiled each of these, and then decompiled them with javad -c, and got:



                > javap -c com.inlet.ifserver.a
                Compiled from "a.java"
                public class com.inlet.ifserver.a
                public com.inlet.ifserver.a();
                Code:
                0: aload_0
                1: invokespecial #1 // Method java/lang/Object."<init>":()V
                4: return

                public final void ThisMethodDoesNothing();
                Code:
                0: return


                > javap -c com.inlet.ifserver.b
                Compiled from "b.kt"
                public final class com.inlet.ifserver.b
                public final void ThisMethodDoesNothing();
                Code:
                0: return

                public com.inlet.ifserver.b();
                Code:
                0: aload_0
                1: invokespecial #11 // Method java/lang/Object."<init>":()V
                4: return



                So I think the answer is a resounding YES! Both do absolutely nothing.






                share|improve this answer













                I figured that the two probably did the same thing, but I had no way to be sure. I really wanted to know. So I created a class to put each of these in (since Java must have a class around any code), changed the Kotlin version so that the attributes on the method were the same, and that gave me this:



                a.java



                public class a 
                public final void ThisMethodDoesNothing()



                b.kt



                class b 
                fun ThisMethodDoesNothing() = Unit



                Then I compiled each of these, and then decompiled them with javad -c, and got:



                > javap -c com.inlet.ifserver.a
                Compiled from "a.java"
                public class com.inlet.ifserver.a
                public com.inlet.ifserver.a();
                Code:
                0: aload_0
                1: invokespecial #1 // Method java/lang/Object."<init>":()V
                4: return

                public final void ThisMethodDoesNothing();
                Code:
                0: return


                > javap -c com.inlet.ifserver.b
                Compiled from "b.kt"
                public final class com.inlet.ifserver.b
                public final void ThisMethodDoesNothing();
                Code:
                0: return

                public com.inlet.ifserver.b();
                Code:
                0: aload_0
                1: invokespecial #11 // Method java/lang/Object."<init>":()V
                4: return



                So I think the answer is a resounding YES! Both do absolutely nothing.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 4:10









                SteveSteve

                4,8101 gold badge8 silver badges31 bronze badges




                4,8101 gold badge8 silver badges31 bronze badges



















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    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%2f55389695%2fis-there-any-difference-between-empty-block-and-unit%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현