a: Int = 1 // val = READ ONLY (getter) var b: Int = 1 // var = READ/WRITE (getter/setter) • String templates "My name is $name $surname" • Lambdas view.setOnClickListener { Log.d("TAG", "Item clicked!") } • Delegated properties (example: lazy) val item by lazy { MyItem() }
"bird" to "tweet", "mouse" to "squeek") fun sound(animal: String): String? { return map.get(animal) } fun example() { val foxSay = sound("fox") ?: "No one knows" } class MyUtils { static Map<String, String> map = // ... static String sound(String animal) { return map.get(animal); } static void example() { String s = sound("fox"); String foxSay = s != null ? s : "No one knows"; } } #6 Kotlin - Elvis Operator http://kotlinlang.org/docs/reference/idioms.html#if-not-null-and-else-shorthand vs
"bird" to "tweet", "mouse" to "squeek") fun sound(animal: String): String? { return map.get(animal) } fun example() { val foxSay = sound("fox") ?: "No one knows" } class MyUtils { static Map<String, String> map = // ... static String sound(String animal) { return map.get(animal); } static void example() { String s = sound("fox"); String foxSay = s != null ? s : "No one knows"; } } #6 Kotlin - Elvis Operator http://kotlinlang.org/docs/reference/idioms.html#if-not-null-and-else-shorthand vs
HeroItem: hair (String?), eyes (String?) - Mostrarle (se presenti) nella lista - Se vengono scelti 2 eroi di sesso opposto, viene creato un nuovo eroe - Si possono usare le proprietà dei genitori, oppure dei valori di default se mancano Start with: https://github.com/jacklt/KotlinExample/tree/ex1 Solution: https://github.com/jacklt/KotlinExample/tree/ex2