Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class ExampleActivity : Activity() {
  2. // the controller variable is guaranteed non-null at the language level (of type `ExampleController` and not `ExampleController?`)
  3. // and behaves effectively as a `val` as setting it twice will throw an exception
  4. var controller: ExampleController by Delegates.notNullVal()
  5. @Inject set
  6.  
  7. override fun onCreate(savedInstanceState: Bundle?) {
  8. super.onCreate(savedInstanceState)
  9. setContentView(R.layout.example_layout)
  10.  
  11. //controller.doThing() // would compile but throw at runtime
  12.  
  13. component().inject(this)
  14.  
  15. controller.doThing() // works, no need for null-safe syntax
  16.  
  17. //controller = createAnotherController() // would throw at runtime
  18. }
  19.  
  20. // ...
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement