Kotlin Demystified: When to use custom accessors

Nicole Borrelli
Aug 28, 2018 · 2 min read
Image for post
Image for post
Photo by Barn Images on Unsplash
val transportControls: MediaControllerCompat.TransportControls
= mediaController.transportControls
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.uamp.next, PID: 18641
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.uamp.next/com.example.android.uamp.MainActivity}:
kotlin.UninitializedPropertyAccessException: lateinit property mediaController has not been initialized
val transportControls: MediaControllerCompat.TransportControls
get() = mediaController.transportControls
@NotNull
private final TransportControls transportControls = mediaController.getTransportControls();
@NotNull
public final TransportControls getTransportControls() {
return this.transportControls;
}
@NotNull
public final TransportControls getTransportControls() {
return mediaController.getTransportControls();
}
val ticket get() = findTicketInDb()
val ticket = findTicketInDb()

Android Developers

The official Android Developers publication on Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store