• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

hashcode & equals - how to check array  RSS feed

 
Ranch Hand
Posts: 140
  • 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
>
 
Rancher
Posts: 618
  • 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
  • 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
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • 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.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for helping Shanky
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!