| Author |
put() method in Hashtable/Hashmap.
|
Kaustubh Patil
Ranch Hand
Joined: Aug 13, 2001
Posts: 164
|
|
hi, the put() method in Hashtable/Hashmap returns a object according to the specification. But even if u just code as hashtable.put() and do no assign the returned object to anything (that is treat the method as returning void) the code still works perfectly .. Why does this happen ?? Thanks, Kaustubh.
|
Kaustubh. Mumbai, India.
|
 |
Mark Herschberg
Sheriff
Joined: Dec 04, 2000
Posts: 6035
|
|
Basically, you'are asking the following. Given a method foo() which returns an object, what's the difference between. In both cases, you call foo(). In both cases, the method works as expected, and in both cases, an object is returned. In the first case, that object is referenced by the variable obj. In the second case, no reference to the object is given. When the method returns, the reference to the object within the method goes out of scope, and is ultimately "dropped." So effectively, you created an object (assuming the method itself created the object), that no has no references, and will be garbage collected. Effectively, the latter statement is equivalent to --Mark
|
 |
Kaustubh Patil
Ranch Hand
Joined: Aug 13, 2001
Posts: 164
|
|
So does this mean that it can happen with any method or just some special methods ? i.e. is it OK if i ignore the object returned from any method ? Kaustubh.
|
 |
 |
|
|
subject: put() method in Hashtable/Hashmap.
|
|
|