Is hashCode of a scala enum is the same on different JVM (spark) ?









up vote
2
down vote

favorite












I read that a good practice for enum is scala is as follow.



I deliberately extends the class with Serializable for Spark.



sealed abstract class MyEnum(val nature: String) extends Serializable
case object A extends MyEnum("a")
case object B extends MyEnum("b")


The problem is that i want that the enum should be extensible by others, thus i have to remove the sealed keyword to enable this functionality



abstract class MyEnum(val nature: String) extends Serializable
case object A extends MyEnum("a")
case object B extends MyEnum("b")


On another file



import enumpackage.MyEnum
case object C extends MyEnum("c")


Knowing this issue with Java enum on Spark, i was wondering how is generate the hashCode from object that extends class that are sealed or not.



Is it safe to avoid sealed keyword for my purpose or do i have to keep it, why ?
If i have to keep it, is there any solution to my extensibility problem.










share|improve this question

























    up vote
    2
    down vote

    favorite












    I read that a good practice for enum is scala is as follow.



    I deliberately extends the class with Serializable for Spark.



    sealed abstract class MyEnum(val nature: String) extends Serializable
    case object A extends MyEnum("a")
    case object B extends MyEnum("b")


    The problem is that i want that the enum should be extensible by others, thus i have to remove the sealed keyword to enable this functionality



    abstract class MyEnum(val nature: String) extends Serializable
    case object A extends MyEnum("a")
    case object B extends MyEnum("b")


    On another file



    import enumpackage.MyEnum
    case object C extends MyEnum("c")


    Knowing this issue with Java enum on Spark, i was wondering how is generate the hashCode from object that extends class that are sealed or not.



    Is it safe to avoid sealed keyword for my purpose or do i have to keep it, why ?
    If i have to keep it, is there any solution to my extensibility problem.










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I read that a good practice for enum is scala is as follow.



      I deliberately extends the class with Serializable for Spark.



      sealed abstract class MyEnum(val nature: String) extends Serializable
      case object A extends MyEnum("a")
      case object B extends MyEnum("b")


      The problem is that i want that the enum should be extensible by others, thus i have to remove the sealed keyword to enable this functionality



      abstract class MyEnum(val nature: String) extends Serializable
      case object A extends MyEnum("a")
      case object B extends MyEnum("b")


      On another file



      import enumpackage.MyEnum
      case object C extends MyEnum("c")


      Knowing this issue with Java enum on Spark, i was wondering how is generate the hashCode from object that extends class that are sealed or not.



      Is it safe to avoid sealed keyword for my purpose or do i have to keep it, why ?
      If i have to keep it, is there any solution to my extensibility problem.










      share|improve this question













      I read that a good practice for enum is scala is as follow.



      I deliberately extends the class with Serializable for Spark.



      sealed abstract class MyEnum(val nature: String) extends Serializable
      case object A extends MyEnum("a")
      case object B extends MyEnum("b")


      The problem is that i want that the enum should be extensible by others, thus i have to remove the sealed keyword to enable this functionality



      abstract class MyEnum(val nature: String) extends Serializable
      case object A extends MyEnum("a")
      case object B extends MyEnum("b")


      On another file



      import enumpackage.MyEnum
      case object C extends MyEnum("c")


      Knowing this issue with Java enum on Spark, i was wondering how is generate the hashCode from object that extends class that are sealed or not.



      Is it safe to avoid sealed keyword for my purpose or do i have to keep it, why ?
      If i have to keep it, is there any solution to my extensibility problem.







      scala apache-spark hashcode






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 16:26









      KyBe

      397520




      397520






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          In programming languages, particularly in Java & Scala enumerations are not extendible by the user, but only by the owner of the enumeration and usually for good reason, control. If you are getting rid of sealed then don't consider it an enumeration, just consider it just like any other class with subclasses or subobjects.



          As for your hashCode. You get that automatically with case class or case object, so there is nothing extra you really need to do.






          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',
            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%2f53240963%2fis-hashcode-of-a-scala-enum-is-the-same-on-different-jvm-spark%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








            up vote
            4
            down vote













            In programming languages, particularly in Java & Scala enumerations are not extendible by the user, but only by the owner of the enumeration and usually for good reason, control. If you are getting rid of sealed then don't consider it an enumeration, just consider it just like any other class with subclasses or subobjects.



            As for your hashCode. You get that automatically with case class or case object, so there is nothing extra you really need to do.






            share|improve this answer
























              up vote
              4
              down vote













              In programming languages, particularly in Java & Scala enumerations are not extendible by the user, but only by the owner of the enumeration and usually for good reason, control. If you are getting rid of sealed then don't consider it an enumeration, just consider it just like any other class with subclasses or subobjects.



              As for your hashCode. You get that automatically with case class or case object, so there is nothing extra you really need to do.






              share|improve this answer






















                up vote
                4
                down vote










                up vote
                4
                down vote









                In programming languages, particularly in Java & Scala enumerations are not extendible by the user, but only by the owner of the enumeration and usually for good reason, control. If you are getting rid of sealed then don't consider it an enumeration, just consider it just like any other class with subclasses or subobjects.



                As for your hashCode. You get that automatically with case class or case object, so there is nothing extra you really need to do.






                share|improve this answer












                In programming languages, particularly in Java & Scala enumerations are not extendible by the user, but only by the owner of the enumeration and usually for good reason, control. If you are getting rid of sealed then don't consider it an enumeration, just consider it just like any other class with subclasses or subobjects.



                As for your hashCode. You get that automatically with case class or case object, so there is nothing extra you really need to do.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 17:59









                Daniel Hinojosa

                79737




                79737



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240963%2fis-hashcode-of-a-scala-enum-is-the-same-on-different-jvm-spark%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







                    這個網誌中的熱門文章

                    What does pagestruct do in Eviews?

                    Dutch intervention in Lombok and Karangasem

                    Channel Islands