Re: I lost the point: purpose of putting objects to null?
From: AnonymousOne (nobody_at_nowhere.org)
Date: 09/23/04
- Next message: AnonymousOne: "Re: Cant run Applets..XP/IE6.0"
- Previous message: Edwin Martin: "Re: how to check whether int is initialized or not in runtime?"
- In reply to: Dado: "I lost the point: purpose of putting objects to null?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 23 Sep 2004 20:23:06 GMT
I personally use this to test if an object was ever set or not. If you
just check for (x == null) without actually SETTING x to null, then the
compiler would give you a "x may not be initialized" error.
Example:
java.sql.Connection c;
try {
c = java.sql.DriverManager.connect(...);
java.sql.Statement s = c.createStatement();
...
}
catch (Throwable thrown) {
// some code here
}
finally {
if (c == null) then c.close();
}
This example would not compile, because "c" is never initialized.
However, if we change the first line to:
java.sql.Connection c = null;
Then the finally block would work.
Dado wrote:
> I lost the point:
> What is purpose of putting objects to null:
>
> If I make a class, JFrame for example, with button which start connection
> dialog, which is class with connection and statement Object.
> And every time I click the button first I put :
> dialog = null
> dialog = new dialog()
>
> What is purpose to put dialog = null when all its objects are stay non-null?
>
>
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.725 / Virus Database: 480 - Release Date: 19.7.2004
>
>
- Next message: AnonymousOne: "Re: Cant run Applets..XP/IE6.0"
- Previous message: Edwin Martin: "Re: how to check whether int is initialized or not in runtime?"
- In reply to: Dado: "I lost the point: purpose of putting objects to null?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|