Kotlinってこんな言語 #jkug

Kotlinってこんな言語 #jkug

Kotlin言語について、その特徴とサードパーティ製ライブラリの簡単な紹介。

14c9795d267f5b85abb98ca5e8780646?s=128

Taro Nagasawa

July 26, 2013
Tweet

Transcript

  1. Kotlinͬͯ͜Μͳݴޠ 2013.7.26 ୈ1ճ͔Θ͍͍Kotlinษڧձ @ngsw_taro

  2. ࿩͢͜ͱ •Kotlin is Կ •؆ܿ •҆શ •3rd Party Library/FW

  3. Kotlin is Կ

  4. Better Java

  5. JetBrains͕։ൃ͍ͯ͠Δ ੩తܕ෇͚ݴޠ for JVM, Android, JavaScript

  6. ΫϥεΦϒδΣΫτ εϚʔτΩϟετ ϥϜμࣜ ߴ֊ؔ਺ null҆શ τϨΠτ ֦ுؔ਺ ܕਪ࿦

  7. Scala࢖͑͹ʁ

  8. ·͔͊֬ʹɻɻ

  9. Kotlinͷઃܭ໨ඪ̍ JavaฒͷίϯύΠϧ଎౓

  10. Kotlinͷઃܭ໨ඪ̎ දݱྗΛҡ࣋ͭͭ͠ ScalaΑΓ΋γϯϓϧʹ

  11. ؆ܿ

  12. val hoge: Int = 5.inc() ͢΂ͯΦϒδΣΫτ ϓϦϛςΟϒܕ͸ͳ͍

  13. ҉໧ͷܕม׵͸ͳ͍ val a: Float = 2 val b: Float =

    2.toFloat() ←NG
  14. ߴ֊ؔ਺/ϥϜμࣜ (1..999).filter { it % 3 == 0 || it

    % 5 == 0 }.reduce { sum, e -> sum + e }
  15. Ϋϥε class Person( val name: String, val age: Int =

    20 )
  16. Ϋϥε class Person( val name: String, val age: Int =

    20 ) ίϯετϥΫλ ϓϩύςΟ σϑΥϧτ஋
  17. Πϯελϯεੜ੒ Person(“Taro”, 25) Person(“Taro”) Person(name=“Taro”)

  18. Πϯελϯεੜ੒ Person(“Taro”, 25) Person(“Taro”) Person(name=“Taro”) ύϥϝʔλলུ ໊લ෇Ҿ਺ new͸ෆཁ

  19. ֦ுؔ਺ τϨΠτ ςϯϓϨʔτࣜ ͦͷଞʹ ͳͲͳͲ

  20. ҆શ

  21. null҆શ Φʔόϔουͷͳ͍ OptionܕͷΑ͏ͳ΋ͷ

  22. val name: String = name() assert(name != null) ஋͸ඞͣ͋Δ

  23. val name: String? = name() ஋͕ͳ͍͔΋

  24. val name: String? = name() val len = name.length ҆શͰͳ͍ͷ͸ېࢭ

    ←NG
  25. val name: String? = name() if(name != null) val len

    = name.length ҆શͳͷ͸OK
  26. val name: String? = name() val len = name?.length ʮ҆શݺͼग़͠ʯ

  27. Ωϟετ δΣωϦΫε ͦͷଞʹ

  28. 3rd Party Library/FW

  29. Kara Web Framework Kotlinݴޠ಺DSLͰϧʔςΟϯά͔ΒϏϡʔ·Ͱ࡞ΕΔ

  30. class IndexView(val task: Task = Task()): HtmlView() { override fun

    render(context: ActionContext) { h2("λεΫͷొ࿥") formFor(task, "/task".link(), FormMethod.post) { p { labelFor("title", "໊݅") textFieldFor("title") } p { labelFor("content", "಺༰") textAreaFor("content") } p { input(inputType = InputType.submit, value = "ొ࿥") } } } }
  31. Spek ಡΈ΍͍͢࢓༷Λهड़͢ΔͨΊͷDSL

  32. public class calculatorSpecs : JUnitSpec() {{ given("a calculator") { val

    calculator = Calculator() on("calling sum with two numbers") { val sum = calculator.sum(2, 4) it("should return the result of adding the first number to the second number") { shouldEqual(6, sum) } } } }} https://github.com/hhariri/spekΑΓҾ༻
  33. Node.kt funKTionale ͦͷଞʹ

  34. ͋Γ͕ͱ͏͍͟͝·ͨ͠