Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ExampleActivity : Activity() {
- // the controller variable is guaranteed non-null at the language level (of type `ExampleController` and not `ExampleController?`)
- // and behaves effectively as a `val` as setting it twice will throw an exception
- var controller: ExampleController by Delegates.notNullVal()
- @Inject set
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.example_layout)
- //controller.doThing() // would compile but throw at runtime
- component().inject(this)
- controller.doThing() // works, no need for null-safe syntax
- //controller = createAnotherController() // would throw at runtime
- }
- // ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement