https://kotlinlang.org logo
#codereview
Title
# codereview
d

Diego Almeida de Oliveira

02/19/2020, 8:12 PM
Hey guys, which one of these approaches you think would be better in terms of performance, memory, etc?
1
Copy code
class Foo {

	private val logger: Logger by lazy { Logger(getApplicationContext()) } 

	fun aFunctionCalledMultipleTimes() {
		logger.doSomething()
	}
}
2
Copy code
class Foo {

	fun aFunctionCalledMultipleTimes() {
		val logger = Logger(getApplicationContext())
		logger.doSomething()
	}
}
s

Shawn

02/19/2020, 8:14 PM
optimizing references to loggers is like the textbook definition of overoptimization
1
makes way more sense logically and is far more ergonomic
d

Daniel

03/02/2020, 7:13 PM
You can even ditch the
by lazy
. Provided the Logger does not do something crazy on initialization
👆 1
4 Views