0

java.md: Add text about finalizers to style guide

Based on java@ discussion:
https://groups.google.com/a/chromium.org/d/topic/java/9WZLCc14oss/discussion

Bug: 149440
Change-Id: Ie36166fe2282af564daafb13fbcb91af1a4ab6c1
Reviewed-on: https://chromium-review.googlesource.com/c/1344889
Reviewed-by: Tommy Nyquist <nyquist@chromium.org>
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Commit-Queue: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611176}
This commit is contained in:
agrieve
2018-11-27 17:47:49 +00:00
committed by Commit Bot
parent 8f5133db01
commit 16c6fe8960

@ -114,6 +114,18 @@ if (org.chromium.base.BuildConfig.DCHECK_IS_ON) {
}
```
### Finalizers
In line with [Google's Java style guide](https://google.github.io/styleguide/javaguide.html#s6.4-finalizers),
never override `Object.finalize()`.
Custom finalizers:
* are called on a background thread, and at an unpredicatble point in time,
* swallow all exceptions (asserts won't work),
* causes additional garbage collector jank.
Classes that need destructor logic should provide an explicit `destroy()`
method.
### Other Android Support Library Annotations
* Use them! They are [documented here](https://developer.android.com/studio/write/annotations).
* They generally improve readability.