I saw two ways to acquire and manage resources. Or:
Resource resource = getResource();
try { }
finally { resource.close(); }
or
Resource resource = null;
try { resource = getResource(); }
finally { if (resource != null) resource.close(); }
I was wondering which style is preferable. The first excludes the condition if, and the second (I suppose) handles the case of a thread interruption immediately after the assignment, but before entering the block try. What other pros and cons do these styles make on top of each other? Which one should I use?
source
share