https://kotlinlang.org logo
#android
Title
# android
m

miha-x64

10/11/2018, 12:33 PM
Bad, very bad code
👍 4
l

luke_c

10/11/2018, 12:37 PM
The google code is? Why?
m

miha-x64

10/11/2018, 12:51 PM
No matter whose. Theoretically, good version of this code is creating DB instance and passing it to constructors of components. It is not possible due to Android design flaws — okay, let's initialize it in
Application
using
lazy
. Hand-written double-checks should be avoided.
@Volatile
is excessive here.
l

louiscad

10/11/2018, 1:20 PM
Here's something to never mess your codebase like this because of application context requirement: https://github.com/LouisCAD/Splitties/blob/master/appctx/README.md
l

luke_c

10/12/2018, 8:33 AM
@miha-x64 do you mean not using a singleton, and instead passing an instance to whatever component needs it? i believe the double check is for double checked lockin
m

miha-x64

10/12/2018, 9:16 AM
@luke_c I mean that we sometimes must use singletons only due to Android design flaws. Double check is 100% for double checked locking, but it's written incorrectly;
lazy
should be used instead.
4 Views