Android apps • Currently includes a view binder • A new plugin buildscript { … dependencies { … classpath “org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version” } }
Interfaces in Java • Can contain code • Can´t contain state • Can declare properties • Properties are abstract for children • A class can extend several traits • A trait can extend another class • Can use parent functions • Can´t call ‘super’ on overriden functions
fun initDrawer() { "..." } } trait SearchActivity : ActionBarActivity { var searchView: SearchView fun initSearch() { "..." } } trait ScrollHeaderActivity : ActionBarActivity { fun initHeader(){ val image = findViewById(R.id.image) as ImageView val title = findViewById(R.id.title) as TextView } }
override val navigationDrawer: DrawerLayout by bindView(R.id.drawer) override var searchView: SearchView by Delegates.notNull() override fun onCreate(savedInstanceState: Bundle?) { super<ActionBarActivity>.onCreate(savedInstanceState) initDrawer() initHeader() initSearch() } }
4, 5) // Mutable val mutableList = ArrayList<Int>() mutableList[0] = 1 val first = mutableList[0] // Map val map = HashMap<String, Int>() map["key"] = 1 val value = map["key"]