4. • Pragmatic language for industry
– Started in 2010
– Open Source
– 1.0 Released in Feb, 2016
• For JVM, Android, and JavaScript
– Interoperability: 100%
• Try online: https://try.kotl.in
20. Java String s = null;
s.length();
Errors At Runtime
Kotlin val s: String
s.length()
val s: String? = null
s.length()
Errors At Compile Time
= null
Nullable
type
21. Check and use val s: String? = …
if (s != null) {
s.length()
}
Check and exit if (s == null) return
s.length()
Rock’n’Roll s?.length()
s!!.length()
(s ?: “…”).length()
24. Java (as seen from Kotlin)
public class JavaClass {
public String foo(List<String> l) {…}
}
String
String?
List<String>
List<String?>
List<String>?
List<String?>?
Safest!
25. Java Interop: All Nullable
javaValue.toString().length() + 1
javaValue?.toString()?.length()!! + 1
val l: List<String> = javaValue?.getList()!!
ArrayList<String?>
33. Some Notes
• Platform Types are Not Denotable!
– String! is notation, not syntax
• Pure Kotlin is Null-Safe
• Kotlin+Java is as safe as Java
• Annotations Still Applicable
– @NotNull String in Java becomes String in Kotlin
• Dynamic Type for JavaScript Interop
– JS is even unsafer than Java