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.
scala apache-spark hashcode
add a comment |
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.
scala apache-spark hashcode
add a comment |
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.
scala apache-spark hashcode
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
scala apache-spark hashcode
asked Nov 10 at 16:26
KyBe
397520
397520
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 10 at 17:59
Daniel Hinojosa
79737
79737
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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