This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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

The hashCode() method of java.lang.Object  RSS feed

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider the following code:

public class Test
{
public static void main(String args[])
{
}
int i;
public boolean equals(Object o)//line1
{
Test t = (Test)o;//line2
if (t.i == this.i)//line3
return true;//line4
return false;//line5
}
public int hashCode() //line6
{
return i * 31;//line7
}

}

On the above program i have some queries:
1.What does it mean to declare (Object o) in line1
2.What does it mean to declare Test t = (Test)o; in line2
3.What does it mean to declare if (t.i == this.i) in line3
4.What does it mean to declare return true; in line4
5.What does it mean to declare return false; in line5
6.what is the need in this program to implement hashCode() method
7.What is the need of hashCode() method to return i*31;why in particular i*31 value is returned

i would be very thankful if i get the queries to be solved.

tx
carl
 
Ranch Hand
Posts: 8934
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this tutorial
http://www.jchq.net/certkey/0902certkey.htm
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!