scala - Comparing String and Enumeration -
I have a calculation slapped for string in JPA. For more comfortable coding, I define the implicit conversions among them. So I can now define the value val person. = "User"
, - person.role
is a type of code "user"
a string so there is a conversion but when I compare these two If I try, I always feel falsely, because def equals (arg0: any):
any
to boolean, so no trigger is triggered. has gone. I need some explicit conversion, but to be able to leave my plan, do you think the best practice is the best solution here?
value ("user")
code> enumeration type Is wal
. And I believe that this does not compare the string name of the implementation value of equal to
I think joining a heavy hand to do this is my own census
and Is making value
so that the name is correct if it is correct.
but uses my code, not with JPA, I always convert the string to MyEnumeration.Value
. It's easy with things:
Object is expanded to e {val user = value ("user")} skeleton & gt; Val a = E.withName ("user") a: E.Value = User
Note that when using withName
, any string You do not get an exception in the calculation that does not match the name.
Then always use the calculator field in your comparison:
scala> A == E User res9: Boolean = true
If JPA only gives a string, and there is no way around it. Then I think the best option is to either convert the value to the string, change the string to string or upgrade the string to the value and compare the value of the values, these types will not be used to compare , Unless you implement any type of extension of the equal
method, and it is difficult.
Comments
Post a Comment