File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hashcode & equals - how to check array

 
Nigel Shrin
Ranch Hand
Posts: 140
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to understand hashcode & equals - how do you check an array attribute? see line 55 below



The hashcodes returned are different, that part appears successful. The equals() is incomplete.
Any help gratefully received!

Thanks
>
 
Tom Reilly
Rancher
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I'll skip the overly verbose coding style. I don't understand your question about line 55. What do you think is wrong?
 
Nigel Shrin
Ranch Hand
Posts: 140
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning Tom - thanks for your reply. I changed line 55 when posting the question, and hadn't realised I'd fixed it. It was late! So I was pleasantly surprised this morning.

How would you have written the equals()? how would you normally compare arrays?

thanks
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can compare arrays with the Arrays class. But be sure to read the javadoc because the methods in it have some curiosities. For instance that Arrays.equals(Object[] a, Object[]b) compares using == and not the equals method.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PLease tell whether line no 55 is giving you compile time error..

there is 1 more error in your code..are you able to figure it out
 
Nigel Shrin
Ranch Hand
Posts: 140
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all,

Shanky, no compile errors now, but I have already added a cast to the data type ArrayHashEquals:


Is that what you were referring to?

I agree it is verbose, but its my first, just trying to get the principles under my belt, delighted its actually working!!
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly you got it....
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tell me one thing whether line no 77 is working fine.......



is this working fine
 
Nigel Shrin
Ranch Hand
Posts: 140
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanky Sohar wrote:tell me one thing whether line no 77 is working fine.......



is this working fine


Hi Shanky - don't worry about that one, its just a dumb typo!


 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OKay thay second compiler error which i was thinking is this only
 
Nigel Shrin
Ranch Hand
Posts: 140
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for helping Shanky
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic