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 & Modern Libraries
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Takuji Nishibayashi
February 24, 2016
Technology
310
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin & Modern Libraries
Takuji Nishibayashi
February 24, 2016
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
160
CameraX使ってみた
takuji31
0
310
kotlinx.datetime 使ってみた
takuji31
0
1.1k
HiltのCustom Componentについて
takuji31
0
380
java.timeをAndroidで使う
takuji31
0
210
KSPを使ってコード生成
takuji31
0
480
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.2k
kotlinx.serialization
takuji31
0
700
kanmoba-returns-02.pdf
takuji31
0
300
Other Decks in Technology
See All in Technology
AI時代のPlaywright活用(システムテストを自動化する ー 実行エンジンにPla ywrightを選んだ理由)
ynisqa1988
2
1k
QA・ソフトウェアテスト研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
600
AIで楽になるはずが、なぜ疲れる?
kinopeee
0
100
AIが当たり前の組織で エンジニアはどう育つか
nishihira
1
1.3k
文字起こし基盤の信頼性
abnoumaru
0
140
探索・可視化・自動化を一本化 Amazon Quickでデータ活用スピードを上げる方法
koheiyoshikawa
0
210
Playwright × AI Agent でE2Eテストはどう変わるか AI駆動テストの可能性と実用検証の結果
taiga7543
2
880
書籍セキュアAPIについて
riiimparm
0
340
Jitera Company Deck
jitera
0
570
システム監視入門
grimoh
2
570
データ活用研修 問いの発見と仮説構築【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
310
キャリアLT会#3
beli68
2
270
Featured
See All Featured
Building AI with AI
inesmontani
PRO
1
1.1k
Six Lessons from altMBA
skipperchong
29
4.4k
Practical Orchestrator
shlominoach
191
11k
Designing for Performance
lara
611
70k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Embracing the Ebb and Flow
colly
88
5.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Transcript
Kotlin & modern libraries @takuji31
@takuji31 (Takuji Nishibayashi) Application Engineer at Hatena
Loves (AVG 160)
Loves Kotlin
Kotlin
Kotlin 1.0.0 released
JVM Language by JetBrains
Like Swift syntax
Like Swift syntax Swift is Kotlin like syntax!
Java Interoperability
Less boilerplate code
Android ready
Pretty name
Kotlin + modern libraries = happy
Dagger2
Provides in module constructor
Java @Module public class AppModule { private final Context context;
public AppModule(Context context) { this.context = context; } @Provides public Context context() { return context; } @Provides public NotificationManager notificationManager(Context context) { return (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); } }
Kotlin (Provider methods) @Module class AppModule( val context: Context )
{ @Provides fun context() : Context = context @Provides fun notificationManager(context: Context) : NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager }
Use property
Kotlin (Constructor property) @Module class AppModule( @get:Provides val context: Context
) { @Provides fun notificationManager(context: Context) : NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager }
Kotlin (Constructor property) @Module class AppModule( @get:Provides val context: Context,
@get:Provides val notificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager ) { }
Provides in component property
Java @Component(modules = AppModule.class) @Singleton public interface AppComponent { Context
context(); NotificationManager notificationManager(); }
Kotlin (functions) @Singleton @Component(modules = arrayOf(AppModule::class)) interface AppComponent { fun
context(): Context fun notificationManager(): NotificationManager }
Use property
Kotlin (properties) @Singleton @Component(modules = arrayOf(AppModule::class)) interface AppComponent { val
context : Context val notificationManager : NotificationManager }
Realm
Constructor and properties
Primary constructor and default value
Java public class User extends RealmObject { @PrimaryKey private String
uuid; private String name; public User() { this(UUID.randomUUID().toString(), null); } public User(String uuid, String name) { this.uuid = uuid; this.name = name; } public String getUuid() {return uuid;} public void setUuid(String uuid) {this.uuid = uuid;} public String getName() {return name;} public void setName(String name) {this.name = name;} }
Kotlin (default constructor) class User constructor() : RealmObject() { @PrimaryKey
var uuid: String? = UUID.randomUUID().toString() var name: String? = null }
Kotlin (with default value) open class User( @PrimaryKey open var
uuid: String = UUID.randomUUID().toString(), open var name: String? = null ) : RealmObject() {}
Computed property in model class
Use extension property
Java public class User extends RealmObject { private Date createdDate;
@Ignore private Instant createdAt; public Date getCreatedDate() {return createdDate;} public void setCreatedDate(Date createdDate) {this.createdDate = createdDate;} public Instant getCreatedAt() { return DateTimeUtils.toInstant(getCreatedDate()); } public void setCreatedAt(Instant createdAt) { setCreatedDate(DateTimeUtils.toDate(createdAt)); } }
Kotlin (property) Not available
Kotlin (extension property) open class User( … open var createdDate:
Date? = null ) : RealmObject() {} var User.createdAt : Instant get() = DateTimeUtils.toInstant(createdDate) set(value) { createdDate = DateTimeUtils.toDate(value) }
Enjoy Kotlin life!