Passing Java objects

Source: Internet
Author: User

Private void test () throws sqlexception {
Resultset rs = query ();
Closeall (RS );
System. Out. println ("535 ...... test of Java object passing:" + RS );
Rs. Close ();
Rs = NULL;
}

Private void closeall (resultset RS) throws sqlexception {

If (RS! = NULL ){
Statement stmt = NULL;
Connection con = NULL;
Stmt = Rs. getstatement ();
Con = stmt. getconnection ();
Rs. Close ();
Rs = NULL;
Stmt. Close ();
Stmt = NULL;
Con. Close ();
Con = NULL;
}

}
Output result: 535 ...... test resultset: org. Apache. commons. DBCP. delegatingresultset @ 2fae4a
--------------
I have set rs = NULL in the closeall method. Why can I print this object? Why not print null?

When an object is passed in Java, the referenced value is copied and transferred; a referenced copy is created. Rs = NULL modified the referenced copy and did not modify the original reference.

However, both references point to the same object. In fact, Rs. Close () has closed the RS object ..

Http://blog.csdn.net/zhaoqiubo/archive/2004/10/27/zhaoqiubo13.aspx

 

System. Out. println ("535 ...... test of Java object passing:" + RS );
The RS printed here is only a handle, not the actual value of Rs. It seems that the address of a place is "No. 100 Earth Road". One day, the building in this place was demolished, although there is no building, this place is still called "No. 100 earth road", but you can build a new building again.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/zhaoqiubo/archive/2004/10/27/154958.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.