I'm currently doing something like this in java to free resources. Do I need to call close on the BufferedWriter object or is it called in the destructor? With regard to Resource1 and Resource2, I must call release and free respectfully. Is this the correct approach with nested trys? Python has a really nice "with statement" which associates resources with a code scope. Does java have the likes?
Resource1 r1 = new Resource1();
try
{
...
Resource2 r1 = new Resource2();
try
{
...
java.io.BufferedWriter f = new java.io.BufferedWriter(new java.io.FileWriter(new java.io.File("f")));
try
{
...
}
finally
{
f.close();
}
}
finally
{
r2.release();
}
}
finally
{
r1.free();
}
UPDATE: I'm using Java 1.6