Omit Data Type

With Kotlin, specifying a data type is optional.

When using Java, we always had to specify a data type. For example, we couldn't write val name = "Daniel" but instead were forced to write String name = "Daniel". We always had to define the type (String, in this example).

However, Kotlin does not require a data type. Here's an example. This is valid Kotlin:

        val firstName: String = "Daniel"

Notice how we have the String data type. We can just as easily omit String:

        val firstName = "Daniel"

Kotlin is smart enough to know that firstName is a String. We can just as easily provide an Int:

        val age = 25

When you need to specify a data type, sometimes it's enough that the class specifies it's type. Here is an example of a ViewModel from Android Architecture Components:

    val firstName = MutableLiveData<String>()

Kotlin knows that firstName is now of type MutableLiveData.

For Loop in Kotlin

More Tutorials

Kotlin Challenge #1

Build a simple contacts manager.

Android Basic Alert Dialog Box
Basic CardView

Basic CardView

Material Design.

Rounded Corners with a Border
Rounded Button in Android Studio

Rounded Button in Android Studio

Create beautiful buttons in XML.

RecyclerView Day 3: Invoicing app

RecyclerView Day 3: Invoicing app

Built with Android Studio and Kotlin.

Build a Ridesharing Android App - Part 1

Build a Ridesharing Android App - Part 1

Getting started is sometimes the hardest part.

setOnClickListener

Add a click listener in Kotlin.

Android Login Layout

Let users sign in.