![]() ![]() ![]() LOCALVARIABLE nonNull Ljava/lang/String L2 元 1 Val nonNull: String = null // compiler error Below is the code to define a String and a String? val canBeNull: String? = null We will start with the simplest case, null safety with a local nullable variable. The same principle can be applied to any other type. But at the end of the day, Kotlin code is still compiled into bytecode and runs on the JVM.Īs an example, today we will find out how Kotlin distinguishes between the String and String? types when the JVM only knows of Ljava/lang/String. Kotlin distinguishes between references that can hold null (nullable types) and references that cannot (non-nullable types). One of Kotlin’s improvements over Java is null safety. Note: phiên bản Tiếng Việt của bài này ở link dưới.
0 Comments
Leave a Reply. |