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
Moyuru Aizawa
November 28, 2016
Programming
0
250
Kotlin頻出表現
Kotlinでよくつかう文/式等
TwitterID変えました。@lvla0805 -> @MoyuruAizawa
Moyuru Aizawa
November 28, 2016
Tweet
Share
More Decks by Moyuru Aizawa
See All by Moyuru Aizawa
graphicsLayer
lvla
0
160
BluetoothDevice.getName()に裏切られた話
lvla
0
250
Jetpack Composeで画像クロップ機能を実装する
lvla
0
920
Jetpack Compose drag gesture and pinch gesture
lvla
1
3.2k
Jetpack Compose Layout API
lvla
1
600
BLEを使ったアプリを継続的に開発するために
lvla
0
900
RecyclerView.ItemAnimator
lvla
1
280
RecycledViewPool
lvla
1
160
CameraX
lvla
2
2.2k
Other Decks in Programming
See All in Programming
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
920
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
930
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
220
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
Arm移行タイムアタック
qnighy
0
330
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
43
13k
Teambox: Starting and Learning
jrom
133
8.8k
A Philosophy of Restraint
colly
203
16k
Optimizing for Happiness
mojombo
376
70k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Making Projects Easy
brettharned
115
5.9k
4 Signs Your Business is Dying
shpigford
180
21k
Transcript
,PUMJOසग़දݱ !MWMB
lvla lvla0805 Ѫᖒ๖ .PZVSV"J[BXB -FBEFOHJOFFSPGQBJST%JWFVSFLB *OD FVSFLB,PUMJO&WBOHFMJTU
+BWB,PUMJO3Y+BWB
None
QBJST $PVQMFT NBUDIHSPVQ *"$ OPXIJSJOH
None
NFFUT
WBM
‣ SFBEPOMZ ‣ جຊWBMΛར༻͍ͯ͠Δɻ ‣ ňͦΕWBSͰ͋Δඞཁ͋Δͷ ʼn ‣ ΈΜͳ+BWBॻ࣌͘ʹpOBMΛ͚ͭΔΑ͏ʹͳͬͨ WBM
val readOnliy = 10 readOnliy = 20 // error
/VMMBCMF
‣ /VMMΛڐ༰͢Δܕͱɺ/VMMΛڋ൱͢Δܕ͕໌֬ʹΘ͚ΒΕ͍ͯΔ ‣ OPU/VMMʹOVMMೖͰ͖ͳ͍͠ɺOVMMBCMFΛೖ͢Δ͜ͱग़དྷͳ ͍ ‣ ৗʹ/VMMΛҙࣝͯ͠ίʔσΟϯά͢Δ͜ͱʹͳΔ /VMMBCMF val nullable:
String? = null var notNull: String = null // error notNull: String = nullable // error
4BGF$BMM
‣ /VMMBCMF͕/VMMͷ߹ɺOVMM͕ฦ٫͞ΕΔɻ ‣ /VMMBCMF͕/VMMͰͳ͍߹ɺ͕࣮ؔߦ͞ΕΔϓϩύςΟͷ͕ฦ٫ ͞ΕΔɻ 4BGF$BMM nullablePerson?.toString() nullablePerson?.age
%FMFHBUFE1SPQFSUJFT
‣ ϓϩύςΟͷॳظԽΛҕৡͰ͖Δ ‣ ॳظԽΛԆͰ͖Δ ‣ ϥΠϑαΠΫϧʹґଘ͢ΔͷͰWBMͰॳظԽͰ͖Δ %FMFHBUFE1SPQFSUJFT val view by
bindView(R.id.view) val string by lazy { getString(R.string.foo) }
&YUFOTJPO'VODUJPO
‣ ܧঝ͢Δࣄͳ͘ɺطଘΫϥεʹؔΛՃͰ͖Δɻ &YUFOTJPO'VODUJPO fun Activity.toWeb(uri: Uri) { startActivity( Intent(Intent.ACTION_VIEW, uri)
) } fun Subscription.addTo(subscriptions: CompositeSubscription) { subscriptions(this) }
4JOHMF&YQSFTTJPO'VODUJPO
‣ ؔͷ࣮͕୯Ұࣜͷ߹ɺฦΓͷએݴɺϒϩοΫɺSFUVSOΛলུ Ͱ͖Δɻ 4JOHMF&YQSFTTJPO'VODUJPO @Provide fun provideApplicationContext() = applicationContext
)JHIFS0SEFS'VODUJPO
‣ ؔΛҾʹͱͬͨΓ ‣ ؔΛฦ٫͢Δؔ ‣ +BWB͕ؔϑΝʔετΫϥεΦϒδΣΫτ͡Όͳ͍͔Β͜Ε͕Ͱ͖ ͳ͍ )JHIFS0SEFS'VODUJPO fun foo(
function: (Int)->Unit ) { … } fun bar(): (Int)->String { … }
‣ 7JFXΛҾʹͱΓ6OJU 㲈7PJE Λฦ٫͢ΔؔͱಉͰ 4". public interface OnClickListener { void
onClick(View var1); }
‣ ؔͭͷΠϯλʔϑΣʔεΛҾʹऔΔؔʹɺؔΛͤ·͢ ‣ هड़ྔΊͬͪΌݮΔʜ 4". view.setOnClickListener({ view -> view.visibility =
View.GONE }) view.setOnClickListener { view -> view.visibility = View.GONE } view.setOnClickListener { it.visibility = View.GONE }
MFU
‣ ؔΛ͢ͱɺͦͷؔΛ࣮ߦͯ͘͠ΕΔɻ ‣ 4BGF$BMMͰMFUΛ࣮ߦ͍ͯ͠ΔͷͰɺOVMMͰͳ͍߹ʹͷΈ࣮ߦ͞Ε Δɻ MFU nullable?.let { it.doSomething }
BQQMZ
‣ Ϩγʔό 'PP'SBHNFOU ͷϓϩύςΟؔΛར༻͢ΔؔΛ͢ ‣ ͦΕΒ͕ద༻͞ΕͨϨγʔό͕ฦ٫͞ΕΔɻ BQQMZ FooFragment().apply { arguments
= Bundle().apply { pustString("key", "value") } }
‣ 4JOHMF&YQSFTTJPO'VODUJPOͱΈ߹ΘͤΔͱ͖ͬ͢Γ BQQMZ fun newInstance() = FooFragment().apply { arguments =
Bundle().apply { pustString("key", "value") } }
EFDMBSJOHQSPQFSUJFTBOE JOJUJBMJ[JOHUIFNGSPNQSJNBSZ DPOTUSVDUPS
‣ ϓϩύςΟͷએݴͱॳظԽΛɺϓϥΠϚϦίϯετϥΫλͰߦ͑Δ ‣ ϗϯτָʜ EFDMBSJOHQSPQFSUJFTBOEJOJUJBMJ[JOHUIFNGSPNQSJNBSZDPOTUSVDUPS class Person(val firstName: String, val
lastName: String, var age: Int) { // ... }
%BUB$MBTT
‣ FRVBMT IBTI$PEF UP4USJOH DPQZ ΛίϯύΠϧ࣌ʹੜͯ͠ ͘ΕΔ ‣ Ξοϓσʔτ͞Εͳ͍FRVBMT ͱ͞Α͏ͳΒͰ͖Δɻ
%BUB$MBTT data class Person(val firstName: String, val lastName: String, var age: Int)
OUBSPLOJU
‣ ֦ுؔΛͬͯBTTFSU5IBUΛ͍͍ײ͡ʹͯ͘͠ΕΔ ‣ ͏͜Ε͕ͳ͍ͱςετॻ͚ͳ͍ʜ LOJU @Test fun test() { (1
+ 2).should be 3 // assertThat(1 + 2, `is`(3)) }
TZTZBHJLNPDLJUP
‣ ֦ுؔΛͬͯNPDLJUPΛ͍͍ײ͡ʹͯ͘͠ΕΔɻ ‣ ͜Εͳ͍ͱςετͰ͖ͳ͍ʜ LNPDLJUP var item: Item = mock()
item.length().invoked.thenReturn(10) item.length().should be 10 item.verify().length()
5IBOLZPV