Copying value of objects, not reference?

This has been bothering me for a while. I learned that when you set one object equal to another you are really just assigning the same reference to both, so that if one is altered they are both altered. Well, how can you set one object equal to the value of another but not the same reference so that altering one will not alter the other. My concern stems from returning arrays in methods. Since the reference itself is passed, any changes I make to the array are permanent, correct, and not just existing inside the method? So I was thinking maybe the best solution would be to use a tmp{] variable that is equal to the VALUE of the array I pass in, and then return that, so the original array is not altered in any way. Is this the customary practice for dealing with such situations? If not, what is typically done? Oh and just for future reference, because it might be of value to know, how DO I copy a value and not a reference? (and yes, that WAS on purpose ;) )

violagirl23 wrote:
My concern stems from passing arrays to [KRC] methods. Since the reference itself is passed, any changes I make to the array are permanent, correct, and not just existing inside the method? So I was thinking maybe the best solution would be to use a tmp{] variable that is equal to the VALUE of the array.Both georgemc and tschodt have already given you some good pointers, I'll try not to reiterate the same advise.
This is an old "problem", discussed at length by folks much smarter than myself, and (IMHO) there still is no definitive question, let alone universal answer. What I mean is that sometimes this ability to modify the contents of a collection or array within a method is highly desirable; and sometimes of course it's just a source of bugs, when a noob calls your method not realising that it modifies the contents of the passed array (which shouldn't make it past unit testing anyway)... So, I think probably the best thing I can do for you is to give you the terms to google.
What you're talking about is called a defensive copy... which, especially with arrays and collections, typically involves a deep copy (make a copy of every attribute of every object, all the way down the reference tree)... as apposed to Arrays.copyOf, which is a shallow copy, i.e. it just copies the references to the "top" objects.
If you're writing a system from scratch you could decide to implement clone methods for everything you ever need to defensive copy. Cloning is ugly, no matter how you cook it. It requires every part of the class heirarchy being cloned to support the clone method (properly).
In the past, I've tried to write a "generic" copy method, in the abstract-base-type of a class heirarchy using reflections. Everything I've tried has "pretty fatal" flaws. The only "proper" solution (AFAIK) is to just implement clone in every single frickin class... and that's a lot more "boiler plate" code than I personally think should be required to implement such a common, mundane task.
Alternately, you could make all your data transfer objects immutable, so a shallow copy (Arrays.copyOf) of the array is enough to protect the calling code from unexpected changes to the array contents because you are passing "a copy" of the references to things-that-cannot-change... So the callee cannot mutate a pointed-to object, and if the callee changes which object an array element points-to, you won't "see" the change... and of course the callee cannot change which array your reference points to, because Java passes references by value.
Google all the italic stuff... Sun's stuff is the best, then lookout for IBM's stuff, and most Wikipedia articles are really good (a few not so good).
HTH. Cheers. Keith.

Similar Messages

  • ManagedAccounts.aspx Object not reference to object

    SETUP: 2x SharePoint 2010 Servers (14.0.5130.5002); 1x SQL 2008 R2
    I setup alot of managed accounts (about 10) and had them setup to automatically generate the new passwords.  After doing this operation, i can no longer access the managedaccounts.aspx page.  I get object not referenced to object.  I read
    a bunch of forums that said the farm account shouldn't be set to autogenerate passwords and it will cause the error.  Next, what i did is setup a new AD account with static password and made it the farm account.  I then deleted the old farm account
    using powershell.  However, even after doing this, i am still getting the same error.  Any ideas? (everything else is working in the farm as far as i can tell.
    04/12/2011 10:38:06.44  w3wp.exe (0x197C)                        0x1FB0 SharePoint Foundation        
     Runtime                        tkau Unexpected System.NullReferenceException: Object reference not set to an instance of an object.   
    at Microsoft.SharePoint.ApplicationPages.ManagedAccountsDataSourceView.FillDataTable(DataTable table, DataSourceSelectArguments selectArguments)     at Microsoft.SharePoint.WebControls.DataTableDataSourceView.Select(DataSourceSelectArguments
    selectArguments)     at Microsoft.SharePoint.WebControls.AdministrationDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)     at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
    DataSourceViewSelectCallback callback)     at System.Web.UI.WebControls.DataBoundControl.PerformSelect()     at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()     at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildContro... 
    04/12/2011 10:38:06.44* w3wp.exe (0x197C)                        0x1FB0 SharePoint Foundation        
     Runtime                        tkau Unexpected ...ls()     at System.Web.UI.Control.EnsureChildControls()    
    at System.Web.UI.Control.PreRenderRecursiveInternal()     at System.Web.UI.Control.PreRenderRecursiveInternal()     at System.Web.UI.Control.PreRenderRecursiveInternal()     at System.Web.UI.Control.PreRenderRecursiveInternal()    
    at System.Web.UI.Control.PreRenderRecursiveInternal()     at System.Web.UI.Control.PreRenderRecursiveInternal()     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) a5dbe0de-bab0-48cc-9d99-9c094490a1f1

    Here is another thread about this:
    http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010setup/thread/406f1817-d687-49d7-9691-26e487fb5577
    However, none of suggestions worked for me.  i can't reinstall our staging farm cause we are in the middle of a migration.  I am probbably going to open a case with MS as it doesn't seem like anyone has any idea about the problem.

  • How to recover from a Sync command that returns a SyncStatus value 8 (Object not found)

    Hello,
    We are using ActiveSync protocol. We have a situation where our local DB is probably in a invalid state where we do a Sync command passing all of our folders (full sync) and one of the folder (or many) doesn't exist anymore.
    The Sync command result doesn't tell us which folder is invalid.
    But the question is more: how should we recover from this "Object not found" error? Should we erase the local database and do a full refresh?
    Status reference:
    http://msdn.microsoft.com/en-us/library/gg675457(v=exchg.80).aspx
    Thanks
    ArchieCoder

    Sorry, that really isn't a Firefox support issue. Contact a Mac support forum or Mac-users group for advice on to solve that issue.

  • Copying an object not it's reference

    Hi,
    is there a function provided by the java API that allows you to copy an object into a new instance as opposed to just copying the reference to that object?

    You could use the clone() method. Refer the documentation for more help.
    Alternatively, you could write the object to an java.io.ObjectOuputStream and read it from java.io.ObjectInputStream.
    This will give you the copy of the object written to ObjectOutputStream.
    -Manish.

  • How to copy the value of object in jdk 1.6

    Hi,
    I want to copy a object from another with out reference.
    clone(0 is not accessable , only can use super.clone() , but if my class don't have the clone() method at all then ..
    can any body tell me how i can do this..
    thanks in advance

    I think i have not able to describe the problem.
    Well lets have a example
    public class A{
    String value1="";
    public A(){
    public String getValue1() {
              return value1;
         public void setValue1(String value1) {
              this.value1= value1;
    Now ,
    A object1 = new A();
    object1.setValue1("first") ;
    A object2 = new A();
    object2 = object1;
    here giving the reference ...so what is happening if i change object1, object2 will also be updated..
    I don't want this ..instade of this i just want a copy of "object1" for object2 , so that object2 will always have same value and will not depend on object1 updation.
    How to do that ? and i don't want also copying each variable value while coping.

  • Default values of columns not transferred in SSIS Transfer Objects Task

    I am working on a project that is creating a new application, my area of the project being the migration of data from the old application database, transforming it, and populating the new database.
    The transformations to the old data are done in a staging database.
    At the end of the process, the staging database ends up with a lot of new applications tables, populated with the migrated legacy data.
    We need to move these tables from the staging database to (initially) our test databases, but ultimately what will be the live database.
    We have tried using the "Transfer SQL Server Objects Task" in SSIS, but have ran into a problem that a lot of the database tables have default values for columns.
    These default values are not brought over.
    Example. Tables contain a "GUID" field, which has a default of value of newid()
    Right clicking and the table generating the CREATE script generates 
    [GUID] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_tbCRM_Client_GUID] DEFAULT (newid()),
    However, the Transfer objects task does not create this default of newid()
    Examining the SQL generated by the Import / Export Wizard when investigating this shows that the wizard generates this column as
    [GUID] uniqueidentifier NOT NULL
    and the column default value is lost.
    Is there something i should be setting somewhere to force SSIS to bring these column definitions over correctly?

     Kaarthik Sivashanmugam wrote:
    This behavior is by design to maintain backward compatibility with the Copy SQL Server Objects task in SQL Server 2000. Only two constraints (Primary key and foreign key constraints) are expected to be copied by Transfer Objects task.
    thank you for you response Sivashanmugam.
    How can I move these tables (of which there are over a hundred) from my staging database into the application database - and keep the table definitions correct?
    I cannot use the transfer objects task, as this will not define the tables correctly.
    I cannot use the import and export wizard, as this will also not define the tables correctly.
    This means I will manually have to code the drop, create and inserts for over a hundred tables?

  • Access via NULL reference object not possible

    Hi friends,
      I have created an wda application which uses the table popin to display data.
      So that i have created a view with two of the  fields as link to action UI element.
      In the Events/Actions of the link to action element i implemented the following logic.
      data wd_table_cell_editor type ref to cl_Wd_view_element.
      data wd_table_column      type ref to cl_wd_table_column.
      data wd_popin             type ref to cl_wd_table_popin.
      data id type string.
    <b> wd_table_cell_editor ?= wd_this->m_view->get_element( id ).</b>
      wd_table_column ?= wd_table_cell_editor->get__parent( ).
      wd_popin = wd_table_column->get_popin( ).
      context_element->set_attribute( name = 'SELECTED_POPIN' value =
    wd_popin->id ).
    So when i click on the link to action in the table column of the field am getting the following error
    <b>Access via NULL reference object not possible.</b>
    While debugging i have noticed that this error was coming at the below step of the code.
    <b>wd_table_cell_editor ?= wd_this->m_view->get_element( id )</b>
    in the m_view->get_element( id ) does not contan any value , its showing as table , as null value cannnot be assigned may be its throwing the above error.
    But i didnt understand why the view is not getting UI element id ....
    Can one please suggest me where might be the wrong....
    Regards
    Sireesha.

    Hi nithya,
      Could you please calrify the doubts for the following q's.
    1. As u said in the above post, i have changed the code to the below.
         data: lr_table type ref to cl_wd_table,
    lr_table_col type ref to cl_wd_table_column.
    lr_table ?= wd_this->m_view->get_element( 'TABLE' ).
    lr_table_col = lr_table->get_column( ID = 'TABLE_CONNECTID' ).
      <b>wd_popin = lr_table_col->get_popin( ).</b>
    (At the above step which is in bold , eventhough there is value in lr_table_col->get_popin , its not assigning a value to the wd_popin, throwing same error NULL etc.,)
      context_element->set_attribute( name = 'SELECTED_POPIN' value =
    wd_popin->id ).
    2. Before changing the code suggested by u, the follwoing was the code from standard example.Its working fine in the application wdr_test_table.I have debugged the code.The value is getting assigned into wd_table_cell_editor.
    The same thing i have done but its failing to assign the value. thats y its throwing null reference error. Here i have a confusion how its assigning a value and y not in the z application.am giving the code below which is in standard and my application.Please clarify these.
    data wd_table_cell_editor type ref to cl_Wd_view_element.
      data wd_table_column      type ref to cl_wd_table_column.
      data wd_popin             type ref to cl_wd_table_popin.
      <b>wd_table_cell_editor ?= wd_this->m_view->get_element( id ).</b>
    ( Note :  wd_this->m_view->get_element contains value but not assigning it to the wd_table_cell_editor and same code in the standard behaving correctly like assigning the view value to the cell editor. Y this behavior, please advice me)
      wd_table_column ?= wd_table_cell_editor->get__parent( ).
      wd_popin = wd_table_column->get_popin( ).
      context_element->set_attribute( name = 'SELECTED_POPIN' value = wd_popin->id )
    Regards
    Sireesha.

  • Can i copy values from one object to another ?

    One more help..
    How do i compare the input values with the ones in an object of another class ?
    Can i copy values of one object of a class to different object of another class ?
    Thanks,
    Sanlearns

    How do i compare the input values with the ones in an
    object of another class ?By getting and comparing them?
    Can i copy values of one object of a class to
    different object of another class ?Yes, you can. But you shouldn't, as you're breaking encapsulation all over the place. You could use setter methods (if available) to set the values.

  • The value in flexfield context reference web bean does not match with the value in the context of the Descriptive flexfield web bean BranchDescFlex. If this in not intended, please go back to correct the data or contact your Systems Administrator for assi

    Hi ,
    We have enabled context sensitive DFF in Bank Branch Page for HZ_PARTIES DFF , We have created Flex Map so that only bank branch context fields are only displayed in the bank branch page and  as we know party information DFF is shared by supplier and Customer Page so we dint want to see any Bank Branch fields or context information in those pages.
    We have achieved the requirement but when open existing branches bank branch update is throwing below error message :
    "The value in flexfield context reference web bean does not match with the value in the context of the Descriptive flexfield web bean BranchDescFlex. If this in not intended, please go back to correct the data or contact your Systems Administrator for assistance."
    this error is thrown only when we open existing branches, if we save existing branch and open then it is not throwing any error message.
    Please let us know reason behind this error message.
    Thanks,
    Mruduala

    You are kidding?  It took me about 3 minutes to scroll down on my tab to get to the triplex button!
    Habe you read the error message? 
    Quote:
    java.sql.SQLSyntaxErrorException: ORA-04098: trigger 'PMS.PROJECT_SEQ' is invalid and failed re-validation
    Check the trigger and it should work again.
    Timo

  • ORA-22806 : not an object or reference in 10gRel2

    Hi,
    We have recently successfully upgraded our oracle 8i database to 10.2.0.1
    database is up and running fine, but
    one of the user created procedure is giving error as below :
    ORA-22806 : not an object or reference
    See the below code :
    =============
    v_cnt:=0;
    Check_Str := 'SELECT COUNT(*) FROM P_EMP_HOLIDAY_DATE
    WHERE company_id=:p_Comp_id
    AND branch_id = :rec_branch.branch_id
    AND employee_id =:rec_emp.employee_id
    AND :v_nxt_date IN holiday_date';
    EXECUTE IMMEDIATE Check_Str INTO v_cnt USING p_Comp_id,rec_emp.branch_id, rec_emp.employee_id,v_nxt_date;
    Put_Any_Line('v_cnt : ' || v_cnt);
    when we run the procedure it gives the error at line 186 .i.e the line with EXECUTE IMMEDIATE statement in above
    so where is the problem ?
    this procedure was running fine without any problem in our oracle 8.1.7.0 version now showing error in 10.2.0.1
    is there any syntax problem that is not being suported in the upgraded version i.e. 10.2.0.1
    how to get it solved ?
    As this is very urgent to solve so any immediate support would be appreciated.
    with regards

    What is Put_Any_Line ? Why are you using dynamic sql here ?
    As this is very urgent to solve so any immediate support would be appreciated.Ok, then please, do not hesitate to use the Oracle support, and see how it can be immediate support.
    Nicolas.

  • Copy functionality which did not copy Long Text values causing us an issue

    Two new Master Recipes created in Bathurst by using copy functionality in transaction C201 contained SRC value errors believed to be caused by changes in the copy
    functionality which did not copy Long Text values causing us an issue when creating Process Orders.   Current workaround is to manually edit the
    value fields and re-save the MRs, the issue is then resolved.

    This will resolve the issue
    SAP Note 1452700 - "New" button is disabled after
    displaying text
    Note Language: English Version: 1 Validity: Valid Since 03/25/2010
    Summary
    Symptom
    In display mode you navigate via the text hyperlink to the text view.
    When you navigate back, the "New" button on the "Notes" assignment block is
    disabled.

  • Passing objects by reference in PL/SQL

    Hi,
    I have come across an unexpected problem using object types in PL/SQL that is causing me some grief. I'm from a Java background and am relatively new to Oracle Objects but what I'm trying to do is fairly trivial, I think. The code below illustrates the problem.
    --- cut here ---
    CREATE OR REPLACE TYPE test_obj_t AS OBJECT
    num INTEGER,
    CONSTRUCTOR FUNCTION test_obj_t RETURN SELF AS RESULT
    CREATE OR REPLACE TYPE BODY test_obj_t IS
    CONSTRUCTOR FUNCTION test_obj_t RETURN SELF AS RESULT IS
    BEGIN
    num := 0;
    RETURN;
    END;
    END;
    CREATE OR REPLACE PACKAGE test_obj_ref AS
    PROCEDURE init(o IN test_obj_t);
    PROCEDURE inc;
    FUNCTION get_num RETURN INTEGER;
    END;
    CREATE OR REPLACE PACKAGE BODY test_obj_ref IS
    obj test_obj_t;
    PROCEDURE init(o IN test_obj_t) IS
    BEGIN
    obj := o;
    END;
    PROCEDURE inc IS
    BEGIN
    obj.num := obj.num + 1;
    END;
    FUNCTION get_num RETURN INTEGER IS
    BEGIN
    RETURN obj.num;
    END;
    END;
    --- cut here ---
    The object type test_obj_t holds a integer and the test_obj_ref package holds a 'reference' to an instance of the object.
    To test the above code I run this PL/SQL block:
    declare
    obj test_obj_t;
    begin
    obj := test_obj_t;
    test_obj_ref.init(obj);
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    test_obj_ref.inc;
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    test_obj_ref.inc;
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    end;
    giving the output:
    obj.num=0
    test_obj_ref.get_num=0
    obj.num=0
    test_obj_ref.get_num=1
    obj.num=0
    test_obj_ref.get_num=2
    It appears that the object held by the test_obj_ref package is being incremented as expected, but I would have expected the object declared in the PL/SQL block to be pointing to the same object and so should report the same incremented values.
    I suspect that the object is copied in the call to test_obj_ref.init() so I end up with two object instances, one that is held by the test_obj_ref package and one in the anonymous block. Although, I thought that all IN parameters in PL/SQL are passed by reference and not copied!
    Am I right?
    Is passing objects by reference possible in PL/SQL, if so how?
    I'm using Oracle 10.2.0.3.
    Cheers,
    Andy.

    the object being passed to the test_obj_ref.init+ procedure is passed by reference; however, when you assign it to your package variable obj it is being copied to a new instance. you can pass object instances as parameters to procedures using the +IN OUT [NOCOPY]+ *calling mode, in which case modifications to the attributes of the passed object will be reflected in the calling scope's instance variable.
    oracle's only other notion of an object reference is the +"REF &lt;object-type&gt;"+ datatype, which holds a reference to an object instance stored in an object table or constructed by an object view.
    hope this helps...
    gerard

  • Does Java pass objects by Reference

    The following is my code:
    public static boolean isValid(String tester, Integer intHours, Integer intMinutes)
              int dotPosition = tester.indexOf('.');
              String hours = tester.substring(0, dotPosition);
              String minutes = tester.substring(dotPosition +1, tester.length());
              try {
                        intHours = Integer.valueOf(hours);
                        intMinutes = Integer.valueOf(minutes);
         } catch (NumberFormatException nfe) {
         return false;
         return true;
    What Iam trying to do is pass the Integer Objects by reference so that they retain their values outside of the scope of the function. My teacher told me that objects are passed by reference in Java but (even though the values are being changed within the function they are not retaining their values outside the scope of the function. Was my teacher wrong?

    aden_jones wrote:
    So to get behaviour similar to passing by reference I would need to create my own object and give it a method e.g. MyObject.changeValue(new_value) but I can't do that with Integer objects because I can't change their actual value I can only change the Integer Object that is being pointed at??You cannot achieve behavior that duplicates PBR with Java.
    However, if by "similar to passing by reference" you mean that the method makes a change that the caller can see, then, yes, you need to pass a reference to a mutable object, and change that object's state inside the method.
    void foo(Bar bar) {
      bar.setBaz(123);
    Bar bar = new Bar();
    bar.setBaz(999);
    foo(bar);
    // after foo() completes, the caller now sees that the Bar object's internal state has changed
    // from 999 to 123Note the difference between changing the value of a caller's variable (which can be done with PBR, and cannot be done in Java) and changing the state of the single object pointed to by both the caller's variable and the method's copy of that variable (which can be accomplished in Java, as it does not rely on PBR).

  • Java is call by value or call by reference

    Hi! friends,
    I want to know,java is call by value and call by reference.
    Please give the the exact explanation with some example code.

    All parameters to methods are passed "by value." In other words, values of parameter variables in a method are copies of the values the invoker specified as arguments. If you pass a double to a method, its parameter is a copy of whatever value was being passed as an argument, and the method can change its parameter's value without affecting values in the code that invoked the method. For example:
    class PassByValue {
        public static void main(String[] args) {
            double one = 1.0;
            System.out.println("before: one = " + one);
            halveIt(one);
            System.out.println("after: one = " + one);
        public static void halveIt(double arg) {
            arg /= 2.0;     // divide arg by two
            System.out.println("halved: arg = " + arg);
    }The following output illustrates that the value of arg inside halveIt is divided by two without affecting the value of the variable one in main:before: one = 1.0
    halved: arg = 0.5
    after: one = 1.0You should note that when the parameter is an object reference, the object reference -- not the object itself -- is what is passed "by value." Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object's state, the object is changed for every part of the program that holds a reference to it. Here is an example to show the distinction:
    class PassRef {
        public static void main(String[] args) {
            Body sirius = new Body("Sirius", null);
            System.out.println("before: " + sirius);
            commonName(sirius);
            System.out.println("after:  " + sirius);
        public static void commonName(Body bodyRef) {
            bodyRef.name = "Dog Star";
            bodyRef = null;
    }This program produces the following output: before: 0 (Sirius)
    after:  0 (Dog Star)Notice that the contents of the object have been modified with a name change, while the variable sirius still refers to the Body object even though the method commonName changed the value of its bodyRef parameter variable to null. This requires some explanation.
    The following diagram shows the state of the variables just after main invokes commonName:
    main()            |              |
        sirius------->| idNum: 0     |
                      | name --------+------>"Sirius"       
    commonName()----->| orbits: null |
        bodyRef       |______________|At this point, the two variables sirius (in main) and bodyRef (in commonName) both refer to the same underlying object. When commonName changes the field bodyRef.name, the name is changed in the underlying object that the two variables share. When commonName changes the value of bodyRef to null, only the value of the bodyRef variable is changed; the value of sirius remains unchanged because the parameter bodyRef is a pass-by-value copy of sirius. Inside the method commonName, all you are changing is the value in the parameter variable bodyRef, just as all you changed in halveIt was the value in the parameter variable arg. If changing bodyRef affected the value of sirius in main, the "after" line would say "null". However, the variable bodyRef in commonName and the variable sirius in main both refer to the same underlying object, so the change made inside commonName is visible through the reference sirius.
    Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If the Java programming language actually had pass-by-reference parameters, there would be a way to declare halveIt so that the preceding code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
    -- Arnold, K., Gosling J., Holmes D. (2006). The Java� Programming Language Fourth Edition. Boston: Addison-Wesley.

  • Confused !HashMap stores an object or reference ?

    HashMap<Integer,Temp> m = new HashMap<Integer, Temp>();
    Temp t1 = new Temp(1); /* pass the id in the constructor */
    m.put(1, t1);
    System.out.println(m.get(1).id); /* This prints out "1" */
    t1.id = 100;
    System.out.println(m.get(1).id); /* This prints out "100" */
    t1 = null;
    System.out.println(m.get(1).id); /* This prints out "100" */
    Since externally modifying the id value of an object of temp class, which has already been inserted in the map, updates the id value of the object stored in the map, I thought that HashMap actually stores a reference and not the entire object. However if I assign a null pointer to t1 externally , still the object in HashMap is not null which means that hashMap has its own copy ??
    Or does java play a smart trick and check whether a non-null object reference is being modified, and if it is, then all of its copies in any of the collections would be updated ?
    Or I am missing something really simple ?

    Remember that t1 is also a reference to the same object as the map. When changing the object through t1's reference the accessing the object through the map will show this change as you specify.
    But, when you set the t1 to reference null (point at nothing) it does not mean the actual object is deleted, lost or changed. It still exists, but now only referenced by the map.
    Consider this:
    Integer a = new Integer(1); // a points to the Integer object
    Integer b = a; // b points to this same object. (not pointing to a, but the same object as a)
    System.out.println( b );
    b = null; // Now b point to null, but the Integer object is still referenced by a
    System.out.println( b );
    System.out.println( a );- Roy

Maybe you are looking for

  • I am unable to upgrade my device because Verizon messed up my contract date

    My current 2 year contract date with Verizon started 9/2012. I have 2 phones on the contract. February of this year I lost 1 phone. I paid FULL price for the phone knowing I was still under contract. Now it seems a Verizon re-aged my contract on that

  • [solved] firefox crashing

    Can someone try "ispreview" from firefox please? As soon as I get to this page it terminates instantly - no attempt to display [paul@night ~]$ firefox http://www.ispreview.co.uk The program 'Gecko' received an X Window System error. This probably ref

  • Backup to Vault Fails Before Switching From Copying Masters to Next Step

    My backup to a Vault in Aperture 3 has failed. I have successfully upgraded to Aperture 3 from Aperture 2. Everything works well, except backing up to a Vault. I have attempted to save the entire library to two different drives - one internal and one

  • Shipping point error in sales order creation

    Dear Friends, I'm new into customizing in SD. I just crested a new plant, distribution channel, shipping point and have assigned the shipping point to the plant. while trying to create sales order i get this warning message "DOCUMENT /00010 HAS NO CH

  • Firefox settings won't load after booting up windows xp

    After starting or rebooting Windows XP, then starting FF 3.69 (really has happened with the last several recent builds 3.6x), my profile will not fully load. Example, all customized icon locations for addons will be missing. If I close, then reopen F