Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kotlin & Modern Libraries
Search
Takuji Nishibayashi
February 24, 2016
Technology
320
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin & Modern Libraries
Takuji Nishibayashi
February 24, 2016
Transcript
38 slides
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!
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
190
CameraX使ってみた
takuji31
0
340
kotlinx.datetime 使ってみた
takuji31
0
1.2k
HiltのCustom Componentについて
takuji31
0
460
java.timeをAndroidで使う
takuji31
0
220
KSPを使ってコード生成
takuji31
0
510
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.3k
kotlinx.serialization
takuji31
0
730
kanmoba-returns-02.pdf
takuji31
0
320
Other Decks in Technology
See All in Technology
仕様と現実の間で落とし所を探るリモートMCPの認証・認可 — Sansanの認証基盤における課題と実践
sansantech
PRO
2
350
BALLAS Technology Deck
ballas_inc
0
830
契約書SaaSにAIエージェントを組み込む
sansantech
PRO
0
180
Context parameters で作る!はじめての型クラス
kworkdev
PRO
1
150
落とし穴にハマってわかった 開発生産性を測るときに気をつけたいこと
munakata
3
380
メール到達性を支える、リンク先URLのドメイン評価の扱い方
wind111
0
130
こんなに変わった! AWSネットワークの常識
shotashiratori
16
9.7k
市販IoT機器や自作IoT機器とHomeAssistantを駆使して家の電気代をできる限り見える化する方法の考案
harutiro
0
360
[関西Kaggler会 20261113] 続・コミュニティコンペのススメ
nejumi
0
140
プロダクションコードにおける encoding/json から encoding/json/v2 へのスムーズな移行
sansantech
PRO
1
440
目を覚ませ!僕らの認証情報が何者かに侵略されてるぞ
tkito
2
450
HTTP通信に使おうとすると実はめんどくさいfile_get_contents
maguroalternative
0
190
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
2
3.9k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
320
Building an army of robots
kneath
307
47k
The Invisible Side of Design
smashingmag
301
52k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
590
Code Review Best Practice
trishagee
74
20k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
580
Scaling GitHub
holman
464
140k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Faster Mobile Websites
deanohume
310
32k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
490
WENDY [Excerpt]
tessaabrams
15
41k