Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
かゆいところに手が届くKotlin
Search
mattak
October 08, 2015
Technology
1.1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
かゆいところに手が届くKotlin
Kotlin's 8 tips.
mattak
October 08, 2015
More Decks by mattak
See All by mattak
人間はどこまでさぼれるか? AIコーディングで人の関与を計測してみた
mattak
0
13
最近やった作業環境改善施策10個
mattak
0
320
UnixTime is Simple
mattak
0
280
おっさんが停滞しないために
mattak
32
19k
tech invest
mattak
1
380
Nodux - node base redux framework
mattak
0
1.6k
what_is_technical_investment
mattak
0
200
unitypackage distribution
mattak
0
900
Unity energy usage
mattak
0
1k
Other Decks in Technology
See All in Technology
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
270
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.9k
自宅NWにISR4331を導入してみた話
okaits
0
110
会社紹介資料 / Sansan Company Profile
sansan33
PRO
24
430k
オートロックマンションなのに、各部屋は施錠なし!? 攻撃者が組織内ネットワークで大暴れする理由 / The Front Door Is Locked, but the Rooms Are Wide Open: Why Attackers Move Freely Inside Enterprise Networks
nttcom
1
6k
Master Dataグループ紹介資料
sansan33
PRO
1
4.8k
モダンフロントエンド 開発研修
recruitengineers
PRO
4
750
Head First モブプログラミング / Head First Mobprogramming
takaking22
10
12k
20分でわかるセキュアAPI
nwiizo
2
300
エンドユーザー視点で見る SansanのMeraki活用と内製自動化
sansantech
PRO
0
100
少人数チームで実現する、大規模AWSサーバーレス基盤における"揺らがない"信頼性運用
maimyyym
1
100
Webアクセシビリティ入門 2026
recruitengineers
PRO
3
640
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
Into the Great Unknown - MozCon
thekraken
41
2.7k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
ラッコキーワード サービス紹介資料
rakko
1
4.4M
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
290
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Technical Leadership for Architectural Decision Making
baasie
3
490
Mobile First: as difficult as doing things right
swwweet
225
10k
Code Review Best Practice
trishagee
74
20k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
490
Ruling the World: When Life Gets Gamed
codingconduct
0
300
Transcript
͔Ώ͍ͱ͜Ζʹ ख͕ಧ͘ ,PUMJO/JHIU !NBUUBL
,PUMJOͷศརͳॻ͖ํͭհ͢ΔΑ
MB[Z ✨ΪϦΪϦ·Ͱ࣮ߦ͠ͳ͍✨
class Person( val firstName: String, val lastName: String ) {
val fullName by lazy { “${firstName}, ${lastName}” } } // ͜ͷ࣌Ͱ fullNameͭ͘ΒΕͳ͍ val person = Person(“John”, “Due”) // ΞΫηεͯ͠ॳΊͯ࡞͞ΕΔ println(person.fullName)
MFU OJMDPBMFTDJOHPQFSBUPS ✨JGMFUͯ͠ฦΓ͕΄͍͠✨
// ී௨ͷॻ͖ํ var name: String? = “Kana” var message: String
= if (name!=null) “Hello, ${name}!” else “Hello.” // let+null coalescing op var name: String? = “Kana” var message: String = name?.let { “Hello, ${it}!” } ?: “Hello.”
DMBTTKBWB ✨KBWBͷΫϥεΦϒδΣΫτ͕΄͍͠✨
// ී௨ͷॻ͖ํ javaClass<Sample>() // M13Ҏ߱ͷॻ͖ํ Sample::class.java // ͍υίϩɺ(TPOύʔε͢Δͱ͖ͳͲ val gson
= Gson() val person = gson.fromJson(“{\”name\”: \”Ocelot\”}”, Person::class.java)
HFUUFSTFUUFS ✨HFUUFSTFUUFS͕͔ΜͨΜʹ͔͚ΔΑ✨
// Computed properties class Duration(val interval: Long) { var seconds:
Double get() = interval.toDouble() / 1000 set(value) { this.interval = value * 1000 } } // javaͷsetter/getter͕KotlinͩͱpropertyʹͳΔΑ person.name = “John” // person.setName(String name) person.name // person.getName()
0CKFDU ✨4JOHMFUPO͕΄͍͠ʂ✨
// java class Singleton { private static Singleton instance =
null; public static Singleton getInstance() { if (instance == null) { instance = new Singleton(); } return instance; } } // kotlin object Singleton() // Objectlazy. ॳճΞΫηεͰOFX͞ΕΔ Singleton
// java class NotSingleton { public static void callClassMethod() {}
} NotSingleton.callClassMethod(); // kotlin class NotSingleton { companion object { fun callClassMethod() {} } } NotSingleton.callClassMethod()
UIJT! ✨ͲͷUIJT͔໌ࣔͯ͠ΞΫηε͍ͨ͠✨
class A { inner class B { fun doit() {
val a = this@A // instance of class A val b = this@B // instance of class B } } }
6OJU ✨+BWBͷ7PJEʹରԠ͢Δͭ✨
public open class UpdateModel { // ΠϕϯτΛૹ৴͍͚ͨ͠ͲɺແҙຯͳΛૹΓ͍ͨ࣌ͱ͔ val updateEvent by
lazy { BehaviorSubject.create<Unit>() } fun update() { // Unit Object. ৽͍͠instanceΛͭ͘Βͳ͍ updateEvent.onNext(Unit) } }
&YUFOTJPO ✨طଘͷΫϥεʹϝιουΛ͚͍ͨ͠✨
// طଘͷΫϥεΛ֦ுग़དྷΔ fun <T> Observable<T?>.notNulls(): Observable<T> { return this.filter {
it != null }. map { it!! } } // ΑΓγϯϓϧʹʂ val observable = Observable.just<Int?>(1, null, 2, null) val normal = observable.filter { it != null }. map { it !! } val pretty = observable.notNulls()
͍͡ΐ͏Ͱ͢ ✨&OKPZLPUMJO✨