of their tools • need for a language that is concise, expressive, toolable, interoperable and pragma6c • Java too slow to catch up • Scala had the right features, but compiler was too slow
in Java .. public static void main(String ... args) { try { Playground.boom(); } catch (IOException cause) { ..} } Does not compile IOException is never thrown in that block
hash;( private String author;( ( public String getAuthor() {( return author;( }( ( public void setAuthor(String author) {( this.author = author;( }( ( public String getHash() {( return hash;( }( ( public void setHash(String hash) {( this.hash = hash;( }( } class Commit(val hash: String, var author: String) val commit = Commit("abc123", "alexhanschke") commit.author = "john.doe" Defaults All classes are public and final by default.
3.squared() // 9 fun List<String>.random(): String { if (this.isEmpty()) { throw IllegalStateException("List must not be empty.") } return this[Random().nextInt(this.size)] } listOf("a", "b", "c").random()
3.squared() // 9 fun List<String>.random(): String { if (this.isEmpty()) { throw IllegalStateException("List must not be empty.") } return this[Random().nextInt(this.size)] } Playground.random(List<String> receiver)
val commit: Commit? = null if (commit != null) { if (commit.author != null) { commit.author.reversed() } } Smart Casts The compiler automagically casts a given type when applicable.