This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Collections_maps  RSS feed

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source: K&B book.. chap 7:

i wanted to clarify about a piece of code, I am not understanding properly..
pasting only relevant parts of code:


in the last case, i am asking it -> m.get(new Dog("clover"))
so the constructor of Dog is called with the name as clover and is returned to m.get method.. why isn't the equal method happy with the object? from where is d1 coming into picture there even if I am not sending a d1?
 
author and jackaroo
Marshal Commander
Posts: 12218
279
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh - how unusual ... Kathy & Bert being extra tricky.

To understand this, you have to understand a couple of things:
  • how Java stores keys and values in a Map (a reference to an object, or a copy of the object (which in turn requires an understanding of passing by reference or passing a copy)).
  • what this means if the key or the value is a mutable object
  • Does that give you a hint as to what might be happening?

    If not, you might want to add this snippet to the MapTest class:

    Then call this method every time something is added to the map, and every time that d1 is modified.
     
    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!