Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android TVとXamarinとKotlin

Android TVとXamarinとKotlin

Mayuki Sawatari

January 21, 2017
Tweet

More Decks by Mayuki Sawatari

Other Decks in Programming

Transcript

  1. ( )

  2. class Greeter(val message: String) { private val prefix = "Hello!"

    fun hello() { println("$prefix $message") } } class Program { fun main() { Greeter("Konnichiwa!").hello() // => Konnichiwa! } }
  3. // 再代入不可 (プロパティも同じ) val valueA = "Hello" valueA = "Konnichiwa!"

    // Compile Error: Val cannot reassigned var valueB = "Hello" valueB = "Konnichiwa!" // OK // null許容 var valueNullable: String? = "Hogehoge" valueNullable = null // null非許容 var valueNonNullable = "Mogemoge" valueNonNullable = null // Error: Null can not be a value of a non-null type String
  4. C# class NanikaData(val valueA: String, val valueB: Int) { }

    NanikaData("Hoge", 1).valueA // => Hoge
  5. (0..10) // ラムダ式のデフォルト引数 it .map({ it * 2 }) //

    カッコ不要 .filter { it > 5 } // 引数に名前を付ける .forEach { i -> println(i) }
  6. val value = NantokaType.ARIENAI // when, if val message =

    when (value) { NantokaType.SUGOI -> "Sugoi" NantokaType.YABAI -> "Yabai" else -> "Majikayo" } println(message) // => "Majikayo" enum class NantokaType { SUGOI, YABAI, ARIENAI }
  7. var valueA: String? = "nantoka" // この時点では null かもしれないので ?.

    または !! が必要 valueA?.substring(0, 3) if (valueA == null) { return } // ここに来れば null ではないと判断され null-safe/non-null assert 不要 valueA.substring(0, 3)
  8. val valueB: Any = "Nantoka" // Any == Object if

    (valueB is String) { valueB.substring(0, 3) // 値が String だと判断できる } valueB.substring // Compile Errorで呼べない TypeScript
  9. interface BaseA { fun hoge() } interface BaseB { fun

    moge() } class BaseAImpl : BaseA { override fun hoge() = println(“BaseA”) } class BaseBImpl : BaseB { override fun moge() = println(“BaseB”) } class AAndBImpl(b: BaseB) : BaseA by BaseAImpl(), BaseB by b { // BaseAの実装BaseAImpl, BaseBはb // mix-in } class NantokaKantoka { fun methodA() { AAndBImpl(BaseBImpl()).hoge() // => BaseA AAndBImpl(BaseBImpl()).moge() // => BaseB } }
  10. IDE

  11. C#