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

ubu

09/10/2018, 10:45 AM
Copy code
class App : Application, SomeBehavior by someObject
@no, this line is invalid, as I have no access to someObject in class declaration.
m

marstran

09/10/2018, 10:52 AM
You can pass one as a parameter:
Copy code
class App(private val someObject: SomeBehaviour) : Application, SomeBehaviour by someObject
p

pablisco

09/10/2018, 10:53 AM
You would need to also have a default constructor, otherwise Android doesn't know how to create the application object
n

no

09/10/2018, 11:23 AM
yeah, looks like you can’t do it then. the default contructor would be the only one constructed by the android system
p

pablisco

09/10/2018, 11:54 AM
I think it'd be ok as long as the default constructor injects that object somehow. If it needs to be set after the application starts then probably some sort of decorator could work.
g

gildor

09/10/2018, 12:23 PM
someObject can be top level property or Singleton, than it will work, but you don't have access to Application in this case, only if you have some lazy semantics and have application instance accessor
👍 1
s

Sam

09/10/2018, 6:25 PM
u

ubu

09/10/2018, 7:17 PM
thanks, I'll check it out
g

gildor

09/10/2018, 11:31 PM
This API added only in Android P, so most applications can use it in probably 5-10 years.