I understand the need for creating getter and setter points for LiveData in the ViewModel. However, I am looking to understand how the get() syntax works in Kotlin.

ie:

Here is a good explanation on Stackoverflow: How Does Android LiveData get() syntax work?

get() is not related to Android.

Here, get() is overriding the automatically-generated Kotlin getter function for the isRealtime property. So, instead of returning its own value, it returns the value of _isRealtime.
Personally, I recommend simpler syntax:

The objective of either of these is to keep the mutability private, so consumers of this class do not accidentally update the MutableLiveData themselves.

--

--

Open Sourcer

Love podcasts or audiobooks? Learn on the go with our new app.

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