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ユーザのためのJSpecify入門 / JSpecify 101 for Kotl...
Search
Kengo TODA
November 21, 2024
Technology
2.4k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
KotlinユーザのためのJSpecify入門 / JSpecify 101 for Kotlin Devs
集まれKotlin好き!Kotlin愛好会 vol.55で発表した内容です。
Kengo TODA
November 21, 2024
More Decks by Kengo TODA
See All by Kengo TODA
セキュリティ担当がいない中小医療機関を院外のRISSはどう支えるべきか / How External RISS Can Help Small Medical Institutions
eller86
1
220
AI といっしょに仕事をする(子供向け)
eller86
0
54
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
200
生成AI 業務応用向けガイドライン 斜め読み / Overview of Generative AI Business Application Guidelines
eller86
0
220
JavaとGroovyで書かれたGradleプラグインをKotlinで書き直した話 / Converted a Gradle plugin from Groovy&Java to Kotlin
eller86
0
1.9k
ヒューマンスキル / The Humanskills
eller86
0
780
医療機関向けシステムの信頼性 / Reliability of systems for medical institutions
eller86
0
550
Server-side Kotlinを使うスタートアップでどんなDetektルールが育ったか / Detekt rules made in start-up working with Server-side Kotlin
eller86
0
1.7k
Java開発者向けのKotlin Gradleビルドスクリプト入門 / Gradle Build Script in Kotlin 101
eller86
1
2.3k
Other Decks in Technology
See All in Technology
メルペイ 会計システム概要と歴史
mewuto
0
190
転んだ話が背中を預ける理由になる / A_story_about_falling_down_gives_you_a_reason_to_watch_each_other_s_backs.pdf
pauli
3
320
Codex概要
ymiya55
0
450
プロダクト価値を、 チームが使える判断軸に変える
vivion
0
130
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
2
2.5k
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
0
130
AI Made Us Faster at Solving the Wrong Problems
marceloancelmo
0
180
自主式軟體工廠
philipz
0
240
SDDの運用にめげずに向き合った話
sansantech
PRO
1
130
Kernel testing frameworks
ennael
PRO
0
110
AI時代だからこそ推したい!Gitコマンド再入門
munakata
0
150
しろおびから始める!ログ活用の第一歩
shumei_ito
0
410
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
420
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
860
The Curse of the Amulet
leimatthew05
3
15k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
720
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
First, design no harm
axbom
PRO
2
1.3k
It's Worth the Effort
3n
188
29k
How to train your dragon (web standard)
notwaldorf
96
6.9k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
550
WCS-LA-2024
lcolladotor
0
850
Transcript
#love_kotlin Kotlinユーザのための JSpecify入門 2024年11月 Kotlin愛好会 Kengo TODA
#love_kotlin JSpecifyとはなんぞ Kotlinでクラスファイルをコンパイルするとorg.jetbrains.annotations パッケージのアノテー ションを使ってnull-abilityに関する情報を補足します。 これはJetBrainsが独自に実装したパッケージで他のツールとの互換性に課題があります。たとえば JSR305やFindBugsが提供しているアノテーションとの互換はありませんし、SpotBugsやPMDといっ た静的解析ツールによるサポートも限定的です。 そこで業界標準アノテーションを作ってこの問題を解決しようとしているのがJSpecifyです。2024 年7月にv1.0リリースもされたので、今からnull-abilityをアノテーションで表明するならJSpecifyが
おすすめです! 2
#love_kotlin そもそもアノテーションとはなんぞ 戻り値や引数、型の使い道など多くの場所を修飾することで、コード生成や静的解析などが使いやす くなるやつ。Koinの @Module や @SingleがKotlinプログラマには身近か。 3 @Module([BarModule::class]) class
FooModule { @Single fun createFoo(): Bar { ... } }
#love_kotlin 静的解析用アノテーションの歴史 18年以上の歴史がある。Java言語機能の不足をアノテーションで補おうというわかりやすい・入りや すく続けにくいアプローチのため、雨後の筍からの兵どもが夢の跡という感じになっている。 4
#love_kotlin 5 https://speakerdeck.com/eller86/goodbye-jsr305-hello-jspecify
#love_kotlin ※ Java SE 8でTYPE_USEが使えるようになった(JSR 308) 6 https://speakerdeck.com/eller86/goodbye-jsr305-hello-jspecify
#love_kotlin Kotlinが静的解析アノテーションをどう使っているか $ javap -v Sample RuntimeInvisibleAnnotations: 0: #13() org.jetbrains.annotations.NotNull
RuntimeInvisibleAnnotations: 0: #15() org.jetbrains.annotations.Nullable // Kotlin class Sample { fun notNull(): Object = Object() fun nullable(): Object? = Object() } 7
#love_kotlin Kotlinコンパイラは、依存先ライブラリのJSpecifyアノテーションを尊重して警告を出せます。 1.5.20以降であればオプションでエラーとして扱うこともできますし、2.1.0からはエラーとして 扱うことを目指しています。 KotlinにとってのJSpecify 8 https://kotlinlang.org/docs/whatsnew1520.html#support-for-jspecify-nullness-annotations compilerOptions { freeCompilerArgs
= listOf( "-Xjspecify-annotations=strict", "-Xtype-enhancement-improvements-strict-mode", ) }
#love_kotlin JSpecifyは今後どうなるか JSpecifyはコミュニティ主導の実装とは言え、最もよく議論・ドキュメントされたアノテーションと しては既に利用価値があります。FindBugsやJSR305などのTYPE_USE未対応アノテーションよりは 優先的に採用したいし、TYPE_USE以外もサポートしてしまっているJetBrainsアノテーションと比べ ても有利な面はあるでしょう。 一方でJava言語公式のDraft JEPとしてnullness markerを作ろうという議論があり、その進展によっ てはKotlinにとってのJSpecifyがオワコン化する可能性は否定できません。
9 https://bugs.openjdk.org/browse/JDK-8303099
#love_kotlin まとめ • Kotlinは2.1.0からJSpecifyを尊重しエラーとして扱うようになる予定 • 自家製JavaライブラリをKotlinから呼んでいる場合、JavaライブラリのAPIをJSpecifyアノ テーションで修飾すると良い ◦ その引数や戻り値のnullnessをうまく扱える ◦
型を変える(Optional<T> にする)よりは導入しやすい • 一方でJSpecifyがデファクトスタンダードになるかは未知数のため、とりあえず採用するとし ても今後の動きは見たほうが良いかも 10