var a: String = null //>> a is non-null type, compilation error var b: String? = null //>> b is nullable, okay val lengthA = a.length //>> okay because a is non-null type val lengthB = b.length //>> error because b might be null. see following usage //>> Usage 1: //>> use safe call operator, written as ?. //>> b?.length return b.length if b is not null and null otherwise //>> the type of lengthB is Int? val lengthB = b?.length //>> Usage 2: //>> let lengthB has default value when b is null and type of lengthB is Int instead of Int? val lengthB: Int = if (b != null) b.length else -1 //>> method 1 val lengthB = b?.length ?: -1 //>> method 2, use Elvis operator, written as ?: //>> Usage 3: //>> use !! operator if you want NullPointerException //>> there will be a NullPointerException when b is null val lengthB = b!!.length