Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Kotlin have an equivalent to Implicitly Unwrapped Optionals in Swift?

Implicitly unwrapped optionals are a useful feature of Swift for things like UI elements that are not assigned during a class's constructor, but can be safely be assumed to be non-null for the majority of functions (as they will have been assigned in a viewDidLoad).

eg.

@IBOutlet weak var textView : UITextView! 

Is there an equivalent for Kotlin, or a workaround that achieves the same effect?

like image 432
stantronic Avatar asked May 03 '17 17:05

stantronic


1 Answers

lateinit var may be a suitable solution. Kotlin just assumes they are not null. https://kotlinlang.org/docs/reference/properties.html#late-initialized-properties

like image 71
Miha_x64 Avatar answered Oct 10 '22 20:10

Miha_x64