Skip to content

Commit

Permalink
java.md: Add text about finalizers to style guide
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
agrieve authored and Commit Bot committed Nov 27, 2018
1 parent 8f5133d commit 16c6fe8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions styleguide/java/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 16c6fe8

Please sign in to comment.