private void test() throws SQLException{ ResultSet rs = query(); closeAll(rs); System.out.println("535........关于java对象传递的测试ResultSet:"+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; }
} 打印出的结果:535........关于java对象传递的测试ResultSet:org.apache.commons.dbcp.DelegatingResultSet@2fae4a -------------- 我在closeAll方法中已经把rs = null;了,为什么还能打印出这个对象呢?为什么不打印出null呢?
在java中传递的是引用;创建了引用的副本。rs=null修改了引用的副本,并没有修改对象本身;所以打印出来的还有。 
|