Slide 1

Slide 1 text

ϓϩάϥϛϯάݴޠ Kotlinͷ঺հ ૣҴాେֶཧ޻ֶज़Ӄ ίϯϐϡʔλ࠙࿩ձ 
 ௕ᖒଠ࿠!OHTX@UBSP ͜ͱΓΜ

Slide 2

Slide 2 text

ࣗݾ঺հ w ௕ᖒଠ࿠!OHTX@UBSP w ਂᖒݚڀࣨ೥ଔۀ ֶ෦ w ࣗশ,PUMJOΤόϯδΣϦετ w ޷͖ͳ΋ͷɺ

Slide 3

Slide 3 text

ΞδΣϯμ +BWBͰ๊͑Δ໰୊ ,PUMJOొ৔

Slide 4

Slide 4 text

1. JavaͰ๊͑Δ໰୊

Slide 5

Slide 5 text

w ߴੑೳɾߴ৴པੑͷ+BWBԾ૝Ϛγϯ w ਐԽΛଓ͚Δϓϩάϥϛϯάݴޠ w ͔͠΋ޙํޓ׵ੑΛҡ࣋ w ྺ࢙௕͍ɺਓޱଟ͍ w ϥΠϒϥϦɾϑϨʔϜϫʔΫଟ͍ Javaૉఢ

Slide 6

Slide 6 text

w ৑௕ɺϘΠϥʔϓϨʔτ w OVMMϙΠϯλͷٯࢀর໰୊ w ܕ҆શੑͷ໰୊ ͔͠͠ɺͦͷ൓໘

Slide 7

Slide 7 text

৑௕ MyFavoriteService s =! new MyFavoriteService<>(banana);

Slide 8

Slide 8 text

ϘΠϥʔϓϨʔτ 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Ϋϥε

Slide 9

Slide 9 text

nullϙΠϯλͷٯࢀর String s = null;! s.toUpperCase(); /VMM1PJOUFS&YDFQUJPO

Slide 10

Slide 10 text

NPE͕ݏͳΒ nullνΣοΫ͢Ε͹͍͍͡Όͳ͍ String s = Ṗͷϝιου();! String upperCase = (s != null)! ? s.toUppserCase()! : null;

Slide 11

Slide 11 text

ͦΕຊ౰ʁ String s = reverse("Hello");! String upperCase = (s != null)! ? s.toUppserCase()! : null;

Slide 12

Slide 12 text

ͦΕຊ౰ʁ String s = reverse("Hello");! String upperCase = (s != null)! ? s.toUppserCase()! : null; OVMM͸ฦ͞ͳͦ͏ɻ ͱ͍͏͔࣮ࡍฦ͞ͳ͍

Slide 13

Slide 13 text

nullͳͷ͔ null͡Όͳ͍ͷ͔ Θ͔Βͳ͍

Slide 14

Slide 14 text

ͱΓ͋͑ͣJavaతͳ޻෉ @Nonnull! String reverse(String s) {…}! ! ! Optional! initial(String s) {…}

Slide 15

Slide 15 text

୭ʹ΋null͸ࢭΊΒΕͳ͍ʂ @Nonnull! Optional findFoo() {! return null;! }

Slide 16

Slide 16 text

ܕ҆શੑͷ໰୊ Integer[] ints = { 0 };! Number[] nums = ints;! nums[0] = 0.5;

Slide 17

Slide 17 text

ܕ҆શੑͷ໰୊ Integer[] ints = { 0 };! Number[] nums = ints;! nums[0] = 0.5; ໌Β͔ʹϚζ͍ૢ࡞ͳͷʹ ίϯύΠϥ͸ؾ෇͔ͳ͍

Slide 18

Slide 18 text

ܕ҆શ͚ͩͲ List ints = immutableListOf(1);! ! List extends Number> nums = ints; ڞมͷ໌ࣔతͳࢦఆ ৑௕

Slide 19

Slide 19 text

w ΋ͬͱ୹͘ɺಡΈ΍͍͢ίʔυΛॻ͖ ͍ͨ w ҆શͳίʔυΛॻ͖͍ͨɻةݥͳίʔ υ͸ίϯύΠϧλΠϜʹ஄͍ͯཉ͍͠ ࢥ͏͜ͱ

Slide 20

Slide 20 text

2. Kotlinొ৔

Slide 21

Slide 21 text

w ೥Նʹ+FU#SBJOTʹΑΓൃද w Φʔϓϯιʔε "QBDIF-JDFOTF w +7.ݴޠɺBMU+4ɺ"OESPJE΋αϙʔτ w +BWBࢿ࢈Λ׆͔ͤΔ w ੩తܕ෇͚ΦϒδΣΫτࢦ޲ݴޠ Kotlinͱ͸

Slide 22

Slide 22 text

w ৑௕ɺϘΠϥʔϓϨʔτ w OVMMϙΠϯλͷٯࢀর໰୊ w ܕ҆શੑͷ໰୊ Kotlinͷ౴͑

Slide 23

Slide 23 text

ܕਪ࿦ // Java! MyFavoriteService s =! new MyFavoriteService<>(banana);! ! ! // Kotlin! val s = MyFavoritesService(banana)

Slide 24

Slide 24 text

ϘΠϥʔϓϨʔτ 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! )

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

nullϙΠϯλͷٯࢀর // Java! String s = null;! s.toUpperCase();! ! // Kotlin! val s1: String = null! val s2: String? = null! s2.toUppserCase() ίϯύΠϧΤϥʔ ܕ ʹର͢Δٯࢀর͸ ؾܰʹͰ͖ͳ͍ʂ

Slide 30

Slide 30 text

KotlinͰ͸ null͔൱͔Λ໌֬ ʹ۠ผ͢Δ ࢀߟIUUQTTQFBLFSEFDLDPNOUBSPLPUMJOOVNCFSTIJCVJHVKWN

Slide 31

Slide 31 text

ܕ҆શ val ints: Array = arrayOf(0)! ! val nums: Array = ints ίϯύΠϧΤϥʔ +BWBελΠϧͷ഑ྻ͸ͳ͍ɻ δΣωϦΫεͰදݱɻ

Slide 32

Slide 32 text

ܕࣗମʹมҐࢦఆͰ͖Δ val ints: List = listOf(0)! ! val nums: List = ints JOUFSGBDF-JTUPVU& ͷΑ͏ʹܕͷఆٛ࣌ʹ มҐΛࢦఆͰ͖Δ

Slide 33

Slide 33 text

w ͔ͳΓ୹͘ɺಡΈ΍͍͢ίʔυ͕ॻ͚ ͦ͏ɻ w ܕͷҧ͍΍OVMMʹΑΔ࣮ߦ࣌ΤϥʔΛ๷ ͍Ͱ҆શͳίʔυ͕ॻ͚ͦ͏ɻ ࢥ͏͜ͱ

Slide 34

Slide 34 text

ͦͷଞͷಛ௕ w ֦ுؔ਺੩తʹطଘܕʹϝιουΛੜ΍ͤ ΔΑ͏ͳ΍ͭ w ߴ֊ؔ਺ɺؔ਺ΦϒδΣΫτɺϥϜμࣜ w +BWBͱͷ૬ޓӡ༻ੑ ໨ඪ w +BWBͱಉ౳ͷίϯύΠϧ଎౓ ໨ඪ w "OESPJE։ൃΛެࣜαϙʔτ

Slide 35

Slide 35 text

w ҆ఆ൛ະϦϦʔε ݱࡏWFS w *%&ͷิॿ͕+BWBͱൺֱͯ͠·ͩऑ͍ w ਓޱɺೝ஌౓͕े෼Ͱͳ͍ ୹ॴ

Slide 36

Slide 36 text

·ͱΊ JavaͰ΋ΜʹΐΓ͢ Δͱ͜ΖɺKotlinͰ͸ ΠΠײ͡ʹͳͬͯΔΑ

Slide 37

Slide 37 text

w IUUQUSZLPUMJOMBOHPSH w खܰʹࢼͤΔ࣮ߦ؀ڥ w ͪΐͬͱ͚ͩಋೖ w ςετίʔυ͚ͩɺ6UJMతͳ΍͚ͭͩ w +BWBͱͷڞଘ͕༰қͳͷͰ ·ͣ࢝ΊΑ͏

Slide 38

Slide 38 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ Let’s enjoy Kotlin!