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

HashMap StackOverflowError problem - please explain me

 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Predict the result !!! and please explain me

HashMap map= new HashMap();
map.put(map,"abdul");

System.out.println(map.get(map));

Regards,

Abdul Mohsin
[ May 18, 2007: Message edited by: Abdul Mohsin ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the links:
One
Second



Thanks,
 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chandra,

thanks for these links but my question is why the above code is giving StackOverflowError

Regards,

Abdul Mohsin
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is the AbstractMap.hashCode(), which uses the hashCode keys to build it. If the keys contains itself, you have an infinite loop.
 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I just gone through the AbstractMap java doc ,but still its not clear why its going in infinite loop.

Regards,

Abdul Mohsin
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic