p
-.kt
l
by lazy { RenderScript.create(context.applicationContext) }
s
How would you pass in the
Context
parameter using
by lazy
??
p
That's what my question is referring to
l
Sorry. Hadn't notice. Well... There is always passing context in constructor, or using dependency injection to inject the application context?
p
There is no constructor, it's a top level function
s
What do you mean there's no constructor? You're initializing a variable in a class, therefore there is a constructor for that class, ain't it?
l
In Kotlin, you have package-functions which don't require being wrapped in a class
s
but
private var rs: RenderScript? = null
is a member of a class, I can't imagine it being a top level variable...
a
@Paul Woitaschek
rs
is a top-level property?
l
There are essentially the same, they are supported as well. As for the initial question, my thoughts are that maybe dependency injection works. Otherwise, I believe it requires a change of architecture. Either creating a singleton holding its reference, or creating a class extending
RenderScript
p
It's a top level property, yes
a
it feels like the job of a DI framework (you are re-implementing singleton with initialization), apart from that IMO there is no better way to initialize that property
1
g
DI is the answer, all other solutions (like Singleton with param) are smell