Habeeb Shaikh wrote:Hi, I think its good idea that whenever we done with our db work, we should close it or set null....
I'd probably create several overloaded "close" methods
That way I wouldn't have to cast and would get a compiler warning if I tried to pass a wrong object to the method
The catch block should only catch SQLException errors
Moreover, you should understand that the dbResource variable contains a copy of the reference
Ivan Jozsef Balazs wrote:>>I'd probably create several overloaded "close" methods
>The reason I wrote this method was exactly yo avoid this.
Interface Closeable might come in useful.
Pranav Raulkar wrote:Since I'm accepting Object in my method, why would compiler flash a warning? Even if one passed another object type, it would get filtered out in the if conditions.
Objetcs are passed by reference. No such thing as copy of reference?
Martin Vajsar wrote:
However, that is not feasible for classes you don't have any control over (such as interfaces that are part of an API).
Martin Vajsar wrote:Are such retrofitted interfaces usable with Java 6? T
Ivan Jozsef Balazs wrote:For example Connection was retrofitted to extend it in with Java v1.7.
However a given concrete implementing class fabricated for say Java v1.5 might or might not extend it.
Ivan Jozsef Balazs wrote:The Closeable interface was introduced with 1.5 and first applied to java.io.* stuff.
For example Connection was retrofitted to extend it in with Java v1.7.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton