Class final variables have to be set when they are declared or in the constructor
Local final variables have to be set at declaration or later
Finalize is called during garbage collection
Finally is part of try.
try with resources eliminates the need for catch. If these cause any exceptions (try-with-resources) swallows them silently.
try-with-resources can still have a finally block.
Bad practice is to throw new exceptions from finally. [We loose context of original exception]
try and finally are also used with locks.
Exceptions in finally are nasty
Final classes cannot be subclassed, java have covarient returns types so for immutability final is required.
final methods cannot be overridden. (Saying dont override this)
static methods are not called polymorphically.
final class variables need to be set or set in a constructor
final local variables can be set once
final method argument are there to ensure that object references cannot be reset unintenionally.
Local final variables have to be set at declaration or later
Finalize is called during garbage collection
Finally is part of try.
try with resources eliminates the need for catch. If these cause any exceptions (try-with-resources) swallows them silently.
try-with-resources can still have a finally block.
Bad practice is to throw new exceptions from finally. [We loose context of original exception]
try and finally are also used with locks.
Exceptions in finally are nasty
lock.lock();
try{
//do critical section code, which may throw exception
} finally {
lock.unlock();
}
Final classes cannot be subclassed, java have covarient returns types so for immutability final is required.
final methods cannot be overridden. (Saying dont override this)
static methods are not called polymorphically.
final class variables need to be set or set in a constructor
final local variables can be set once
final method argument are there to ensure that object references cannot be reset unintenionally.
No comments:
Post a Comment