commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Pokotilo (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-780) add public org.apache.commons.lang.builder.HashCodeBuilder append(Enum value) to HashCodeBuilder
Date Tue, 13 Dec 2011 02:17:31 GMT

    [ https://issues.apache.org/jira/browse/LANG-780?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13168068#comment-13168068
] 

Alex Pokotilo commented on LANG-780:
------------------------------------

enum hashCode is different between JVM instances. so adding append(Enum value) will covern
this case.


Following example will cover what I'm talking about

public class j
{

	enum TestEnum
	{
		ONE,
		TWO
	}

	private static int hashCodeForEnum(Enum enumItem)
	{
	   return enumItem.name().hashCode();
	}

	public static void main(String[] args)
	{
		TestEnum e = TestEnum.ONE;	
		System.out.print(e.hashCode());
		System.out.print(" ");
		System.out.print(hashCodeForEnum(e));
	}
}


System.out.print(hashCodeForEnum(e)); will always return the same value but System.out.print(e.hashCode());
will not . I want HashCodeBuilder cover this for me.
                
> add  public org.apache.commons.lang.builder.HashCodeBuilder append(Enum value) to HashCodeBuilder

> --------------------------------------------------------------------------------------------------
>
>                 Key: LANG-780
>                 URL: https://issues.apache.org/jira/browse/LANG-780
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.builder.*
>    Affects Versions: 2.5
>            Reporter: Alex Pokotilo
>   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
> public org.apache.commons.lang.builder.HashCodeBuilder append(Enum value)
> {
>  append(value.name().hashCode());
>  return this;
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message