Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Rep Power

    Default creating a reference to a value in a map

    can i do the following

    gum=new Gum()

    mapOfGum is a map of different pieces of Gum, key=String flavorName

    i would like gum to reference the peppermint piece in mapOfGum

    i can easily get a copy of the peppermint piece and assign it to gum, but i only want 1 gum that is peppermint, the 1 that resides in the map. because gum takes up space.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    There is only one copy when retrieving it from the map. When you get a new reference from the map, you are getting just that, a reference, not a copy of the object. Think of the reference as being a String tied to the instance with you holding the other end. Getting another reference (i.e. retrieving a "copy" from the HashMap) simply ties another String to the instance.

Similar Threads

  1. Object and reference
    By katie in forum New To Java
    Replies: 2
    Last Post: 10-19-2009, 04:45 PM
  2. removing reference
    By ajith_raj in forum Advanced Java
    Replies: 4
    Last Post: 02-12-2009, 12:46 PM
  3. Replies: 0
    Last Post: 04-15-2008, 09:12 AM
  4. Getting the Object Reference Name
    By Deathmonger in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 03:51 PM
  5. reference to elements in array
    By Igor in forum New To Java
    Replies: 1
    Last Post: 12-14-2007, 12:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts