Kotlin: val vs var

What's the difference?

Kotlin provides two ways to define variables: val and var. What's the difference? You can change var variables as many times as you want. But once you set a val variable, you can't update again. Here's an example:

val firstName = "Daniel" // always stuck with "Daniel", can't change anymore

From now on, you can't change firstName; it's set in stone. However, had I created firstName with var, I can change it:

var firstName = "Daniel"
firstName = "Dan"
firstName = "John"
firstName = "Don"

In general, prefer val, unless the variables needs to change.

setOnClickListener

More Tutorials

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.

Registration Screen

Registration Screen

It always begins with registration.