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
1.1k
かゆいところに手が届くKotlin
Kotlin's 8 tips.
mattak
October 08, 2015
Tweet
Share
More Decks by mattak
See All by mattak
最近やった作業環境改善施策10個
mattak
0
300
UnixTime is Simple
mattak
0
250
おっさんが停滞しないために
mattak
32
18k
tech invest
mattak
1
360
Nodux - node base redux framework
mattak
0
1.6k
what_is_technical_investment
mattak
0
160
unitypackage distribution
mattak
0
880
Unity energy usage
mattak
0
970
Unidux 0.3.1
mattak
1
440
Other Decks in Technology
See All in Technology
夢の無限スパゲッティ製造機 #phperkaigi
o0h
PRO
0
160
僕、S3 シンプルって名前だけど全然シンプルじゃありません よろしくお願いします
yama3133
1
230
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
2
13k
NewSQL_ ストレージ分離と分散合意を用いたスケーラブルアーキテクチャ
hacomono
PRO
4
400
Postman v12 で変わる API開発ワークフロー (Postman v12 アップデート) / New API development workflow with Postman v12
yokawasa
0
140
社内レビューは機能しているのか
matsuba
0
150
Yahoo!ショッピングのレコメンデーション・システムにおけるML実践の一例
lycorptech_jp
PRO
1
230
PMとしての意思決定とAI活用状況について
lycorptech_jp
PRO
0
140
システム標準化PMOから ガバメントクラウドCoEへ
techniczna
1
140
実践 Datadog MCP Server
nulabinc
PRO
2
240
OSC仙台プレ勉強会 AlmaLinuxとは
koedoyoshida
0
190
モジュラモノリス導入から4年間の総括:アーキテクチャと組織の相互作用について / Architecture and Organizational Interaction
nazonohito51
1
360
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
980
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
Everyday Curiosity
cassininazir
0
170
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
The untapped power of vector embeddings
frankvandijk
2
1.6k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.7k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
230
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
560
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
480
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✨