You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Duncan Jones (JIRA)" <ji...@apache.org> on 2014/10/10 08:49:33 UTC
[jira] [Comment Edited] (LANG-780) Add HashCodeBuilder.append(Enum
value)
[ https://issues.apache.org/jira/browse/LANG-780?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13168966#comment-13168966 ]
Duncan Jones edited comment on LANG-780 at 10/10/14 6:49 AM:
-------------------------------------------------------------
{quote}
Using Enum#name() means that the same hashCode will be used for different Enum instances that happen to have the same name.
That seems like quite a disadvantage to me.
{quote}
Proposed method is just an example and to avoid your concent we can use something like following
{code:java}
private static int hashCodeForEnum(Enum enumItem)
{ return (enumItem.getClass().getName()+enumItem.name()).hashCode(); }
{code}
But again this is just proposal. I think initial point is valid. I want to see the same hashCode for enum using HashCodeBuilder. This would be great.
was (Author: jakop):
"Using Enum#name() means that the same hashCode will be used for different Enum instances that happen to have the same name.
That seems like quite a disadvantage to me."(c)
Proposed method is just an example and to avoid your concent we can use something like following
private static int hashCodeForEnum(Enum enumItem)
{ return (enumItem.getClass().getName()+enumItem.name()).hashCode(); }
But again this is just proposal. I think initial point is valid. I want to see the same hashCode for enum using HashCodeBuilder. This would be great.
> Add HashCodeBuilder.append(Enum value)
> --------------------------------------
>
> Key: LANG-780
> URL: https://issues.apache.org/jira/browse/LANG-780
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.builder.*
> Affects Versions: 2.5
> Reporter: Alex Pokotilo
> Fix For: Review Patch
>
> Attachments: LANG-780.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> Since Enum's hashCode return different values between calls this can cause different values if enum appended to HashCodeBuilder
> IMHO adding append for enum would be enough to solve this entirely
> {code:java}
> public org.apache.commons.lang.builder.HashCodeBuilder append(Enum value)
> {
> append(value.name().hashCode());
> return this;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)