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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
240
AI といっしょに仕事をする(子供向け)
eller86
0
58
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
230
生成AI 業務応用向けガイドライン 斜め読み / Overview of Generative AI Business Application Guidelines
eller86
0
230
JavaとGroovyで書かれたGradleプラグインをKotlinで書き直した話 / Converted a Gradle plugin from Groovy&Java to Kotlin
eller86
0
2k
ヒューマンスキル / The Humanskills
eller86
0
790
医療機関向けシステムの信頼性 / Reliability of systems for medical institutions
eller86
0
560
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
Content Mapper APIの応用例~CSS Modules、言語ファイル~
uhyo
2
580
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
1
210
これだけは抑えておきたい!後悔しない re:Invent の過ごし方 / AWS re:Invent 2026 prestudy
kinunori
2
700
AWSを利用する上で知っておきたい名前解決の話 2026
nagisa53
2
460
You Have Agency(サンキュー、Ruby)
snoozer05
PRO
5
680
詳解 never 型 - ボトム型の性質を深掘り
nealle
0
150
生成AI時代のIAMのマニアックな話
takuros
4
370
Deep Data Security 機能解説
oracle4engineer
PRO
3
1k
Jev の中身は50行で再現できる。でも本物との差はどこにあるのか
hisuzuya
0
300
AWS構成から考えるWebセキュリティ ― WordPressの構築経験から考える公開範囲と更新運用【JAWS FESTA 2026 in AKITA】
cscengineer
PRO
1
140
Don't write the architecture only in the prompt.
neohsu
0
310
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
790
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
560
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
290
WCS-LA-2024
lcolladotor
0
970
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
600
The Cult of Friendly URLs
andyhume
79
7.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.7k
Scaling GitHub
holman
464
140k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
470
A Tale of Four Properties
chriscoyier
163
24k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Statistics for Hackers
jakevdp
799
230k
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