Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jada Mohammad   on Jun 28 In Java Category.

  
Question Answered By: Adalric Fischer   on Jun 28

When you pass  a object  (whatever its type is) to a method, the thing
that happens is that it is created another reference (or pointer,
dont really know) to that object. In your case, if you pass a
Connection object to a method, you are passing  not the object itself
but its reference. So it's not creating a new object nor a new
database connection. Feel free to use it :P . The Garbage Collector
will only "delete" that object if it is no longer referenced in any
point of your program. If you create  a connection  in a method  (M1)
and use it in another method (M2) it will only collect it when both
M1 and M2 are finished or are no longer referencing that object!

Share: 

 
 
Didn't find what you were looking for? Find more on Passing a Connection to a method Or get search suggestion and latest updates.


Tagged: