Hey guys, which one of these approaches you think ...
# codereview
d
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
optimizing references to loggers is like the textbook definition of overoptimization
1
makes way more sense logically and is far more ergonomic
d
You can even ditch the
by lazy
. Provided the Logger does not do something crazy on initialization
👆 1