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

プログラミング言語 Kotlinの紹介

プログラミング言語 Kotlinの紹介

コンこん会で発表した資料です。

Avatar for Taro Nagasawa

Taro Nagasawa

June 27, 2015
Tweet

More Decks by Taro Nagasawa

Other Decks in Programming

Transcript

  1. ϘΠϥʔϓϨʔτ public final class Fruit {! ! private final String

    name;! ! private final int price;! ! private final Country country;! ! public Fruit(final String name, final int price, final Country country) {! this.name = name;! this.price = price;! this.country = country;! }! ! public String getName() {! return name;! }! ! public int getPrice() {! return price;! }! ! public Country getCountry() {! return country;! }! ! public Fruit withName(final String name) {! return new Fruit(name, price, country);! }! ! public Fruit withPrice(final int price) {! return new Fruit(name, price, country);! }! ! public Fruit withCountry(final Country country) {! return new Fruit(name, price, country);! }! ! // toStringͱ͔! // equalsͱ͔! // hashCodeͱ͔! ! public static Builder builder() {! return new Builder();! }! ! public static class Builder {! ! private String name;! ! private int price;! ! private Country country;! ! public Fruit build() {! return new Fruit(name, price, country);! }! ! public Builder name(final String name) {! this.name = name;! return this;! }! ! public Builder price(final int price) {! this.price = price;! return this;! }! ! public Builder country(final Country country) {! this.country = country;! return this;! }! }! } 'SVJUͷఆٛ w QSJWBUFpOBMϑΟʔϧυ w ίϯετϥΫλ w HFUUFS w UP4USJOH FRVBMT IBTI$PEF w #VJMEFSΫϥε
  2. ͦΕຊ౰ʁ String s = reverse("Hello");! String upperCase = (s !=

    null)! ? s.toUppserCase()! : null; OVMM͸ฦ͞ͳͦ͏ɻ ͱ͍͏͔࣮ࡍฦ͞ͳ͍
  3. ܕ҆શੑͷ໰୊ Integer[] ints = { 0 };! Number[] nums =

    ints;! nums[0] = 0.5; ໌Β͔ʹϚζ͍ૢ࡞ͳͷʹ ίϯύΠϥ͸ؾ෇͔ͳ͍
  4. ϘΠϥʔϓϨʔτ public final class Fruit {! ! private final String

    name;! ! private final int price;! ! private final Country country;! ! public Fruit(final String name, final int price, final Country country) {! this.name = name;! this.price = price;! this.country = country;! }! ! public String getName() {! return name;! }! ! public int getPrice() {! return price;! }! ! public Country getCountry() {! return country;! }! ! public Fruit withName(final String name) {! return new Fruit(name, price, country);! }! ! public Fruit withPrice(final int price) {! return new Fruit(name, price, country);! }! ! public Fruit withCountry(final Country country) {! return new Fruit(name, price, country);! }! ! // toStringͱ͔! // equalsͱ͔! // hashCodeͱ͔! ! public static Builder builder() {! return new Builder();! }! ! public static class Builder {! ! private String name;! ! private int price;! ! private Country country;! ! public Fruit build() {! return new Fruit(name, price, country);! }! ! public Builder name(final String name) {! this.name = name;! return this;! }! ! public Builder price(final int price) {! this.price = price;! return this;! }! ! public Builder country(final Country country) {! this.country = country;! return this;! }! }! } data public class Fruit(! val name: String,! val price: Int,! val country: Country! )
  5. nullϙΠϯλͷٯࢀর // Java! String s = null;! s.toUpperCase();! ! //

    Kotlin! val s1: String = null! val s2: String? = null! s2.toUppserCase()
  6. nullϙΠϯλͷٯࢀর // Java! String s = null;! s.toUpperCase();! ! //

    Kotlin! val s1: String = null! val s2: String? = null! s2.toUppserCase() /1&
  7. nullϙΠϯλͷٯࢀর // Java! String s = null;! s.toUpperCase();! ! //

    Kotlin! val s1: String = null! val s2: String? = null! s2.toUppserCase() ίϯύΠϧΤϥʔ ௨ৗͷܕͷม਺ʹɺ OVMM͸୅ೖͰ͖ͳ͍
  8. nullϙΠϯλͷٯࢀর // Java! String s = null;! s.toUpperCase();! ! //

    Kotlin! val s1: String = null! val s2: String? = null! s2.toUppserCase() ܕ  ͸OVMMͰ΋0,
  9. nullϙΠϯλͷٯࢀর // Java! String s = null;! s.toUpperCase();! ! //

    Kotlin! val s1: String = null! val s2: String? = null! s2.toUppserCase() ίϯύΠϧΤϥʔ ܕ ʹର͢Δٯࢀর͸ ؾܰʹͰ͖ͳ͍ʂ
  10. ܕ҆શ val ints: Array<Int> = arrayOf(0)! ! val nums: Array<Number>

    = ints ίϯύΠϧΤϥʔ +BWBελΠϧͷ഑ྻ͸ͳ͍ɻ δΣωϦΫεͰදݱɻ
  11. ܕࣗମʹมҐࢦఆͰ͖Δ val ints: List<Int> = listOf(0)! ! val nums: List<Number>

    = ints JOUFSGBDF-JTUPVU& ͷΑ͏ʹܕͷఆٛ࣌ʹ มҐΛࢦఆͰ͖Δ