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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
200
AI といっしょに仕事をする(子供向け)
eller86
0
52
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.2k
Other Decks in Technology
See All in Technology
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
2.4k
時うどん〜Socket.getifaddrsで学ぶネットワーク編 / Tokiudon: The Socket.getifaddrs Edition
coe401_
4
230
Genieを崇めよ
kameitomohiro
0
170
JSONataとAWS Step Functionsで目指すRuntimelessな世界
mu7889yoon
0
440
AIエージェントの自己改善をどう設計するか / How to Design Self-Improvement for AI Agents
22mi
26
17k
2026-09-18 gotanda.sre Terraformで複数環境作ったり、複数Stateに分割したりそれとTerragrunt / Terraform multi envs and multi states
masasuzu
4
700
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
2.4k
アクセスキーこわい やめかたと漏らさない工夫
sassssan68
1
660
Antigravity SDK for the Java Developer
glaforge
0
180
銀行勘定系システムにおける開発プロセス刷新×AIによる環境モダナイゼーション / Development Process Transformation and AI-Driven Environment Modernization
muit
1
2.6k
Kiro Meetup #8 Kiro アップデート (2026/3/21〜2026/9/24)
katzueno
1
150
AI de Idea
kawaguti
PRO
2
130
Featured
See All Featured
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
How to make the Groovebox
asonas
2
2.4k
How STYLIGHT went responsive
nonsquared
100
6.3k
Ethics towards AI in product and experience design
skipperchong
2
380
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
560
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.9k
Scaling GitHub
holman
464
140k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
Faster Mobile Websites
deanohume
310
32k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
540
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