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ユーザのためのJSpecify入門 / JSpecify 101 for Kotl...
Search
Kengo TODA
November 21, 2024
Technology
2k
0
Share
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
生成AI 業務応用向けガイドライン 斜め読み / Overview of Generative AI Business Application Guidelines
eller86
0
170
JavaとGroovyで書かれたGradleプラグインをKotlinで書き直した話 / Converted a Gradle plugin from Groovy&Java to Kotlin
eller86
0
1.8k
ヒューマンスキル / The Humanskills
eller86
0
750
医療機関向けシステムの信頼性 / Reliability of systems for medical institutions
eller86
0
520
Server-side Kotlinを使うスタートアップでどんなDetektルールが育ったか / Detekt rules made in start-up working with Server-side Kotlin
eller86
0
1.6k
Java開発者向けのKotlin Gradleビルドスクリプト入門 / Gradle Build Script in Kotlin 101
eller86
1
2.1k
Goodbye JSR305, Hello JSpecify!
eller86
2
5.5k
Java8〜16におけるバイトコード生成の変化 / Changes of Bytecode Generation from Java 8 to 16
eller86
4
4.7k
Javaプログラミングの体験向上に関する活動 / DX enhancement around Java programming
eller86
0
3.9k
Other Decks in Technology
See All in Technology
AIと乗り切った1,500ページ超のヘルプサイト基盤刷新とさらにその先の話
mugi_uno
1
210
変化の激しい時代をゴキゲンに生き抜くために 〜ストレスマネジメントのススメ〜
kakehashi
PRO
1
520
COBOL婆さんの伝説
poropinai1966
0
130
ハーネスエンジニアリングをやりすぎた話 ~そのハーネスは解体された~
gotalab555
5
1.9k
需要創出(Chatwork)×供給(BPaaS) フライホイールとMoat 実行能力の最適配置とAI戦略
kubell_hr
0
1.6k
20260423_執筆の工夫と裏側 技術書の企画から刊行まで / From the planning to the publication of technical book
nash_efp
3
690
「誰一人取り残されない」 AIエージェント時代のプロダクト設計思想 Product Management Summit 2026
mizushimac
1
2.5k
AI バイブコーティングでキーボード不要?!
samakada
0
670
GKE Agent SandboxでAIが生成したコードを 安全に実行してみた
lamaglama39
0
170
世界の中心でApp Runnerを叫ぶ FINAL
tsukuboshi
0
160
Building a Study Buddy AI Agent from Scratch: From Passive Chatbots to Autonomous Systems
itchimonji
0
110
要件定義の精度を高めるための型と生成AIの活用 / Using Types and Generative AI to Improve the Accuracy of Requirements Definition
haru860
0
260
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
3.7k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
170
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
730
sira's awesome portfolio website redesign presentation
elsirapls
0
230
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
280
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
160
Documentation Writing (for coders)
carmenintech
77
5.3k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
170
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.7k
A Tale of Four Properties
chriscoyier
163
24k
New Earth Scene 8
popppiees
3
2.1k
How to Ace a Technical Interview
jacobian
281
24k
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