Basic KotlinTips — 1

Sachin Shelar
Jan 15, 2022

--

1. Nullable(?) Types

The variable can Store Null Value

eg: Val title: String?=null

2. lateinit

It means initialise variable or object later in program. And it is allowed only with mutable properties.

eg: lateinit var viewModel:MainViewModel

3. Unit Return Type

In Kotlin if we did not specify the return type for the method then the default return type of all methods is Unit

4. Public Access Modifier

In Kotlin if we did not specify the access modifier, Public is a default access modifier for a class or method.

5. Single Statement Function

It is a function that has a single return statement. Take look of below example.

Example:fun getTitle():String = "Java & Kotlin"fun getUserData():UserInfoEntity = userDao.getLoginUserDetails()

--

--

Sachin Shelar
Sachin Shelar

Written by Sachin Shelar

Android | iOS | Flutter | React Native

No responses yet