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
230
AI といっしょに仕事をする(子供向け)
eller86
0
56
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
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
Benchmarking Disaggregated Serving on vLLM + Dynamo with a Real Coding-Agent Workload
nttcom
0
130
スキマバイトという雇用形態は存在しないので、雇用期間1日のアルバイト契約を事業者とワーカーが結ぶ手続きを支えるのがタイミーなんです
akitoshiga
0
180
Webの常識が通じないHTMLメールのダークモード
teamlab
PRO
0
110
「Docker Desktop不要の時代」は 来たのか?
ueponx
0
650
Refining Active Record
shugo
0
110
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
710
会社説明資料
persolserverworks
0
9.7k
転んだ話が背中を預ける理由になる / A_story_about_falling_down_gives_you_a_reason_to_watch_each_other_s_backs.pdf
pauli
3
370
M5Stackで作る BLEマウス GPSログの世界
tomokusaba
0
300
Deep Data Security 機能解説
oracle4engineer
PRO
2
800
AI時代に必要な脅威モデリング― 変化の速度に負けない理解とリスク判断
masakane55
5
1.3k
不可逆な意思決定を避けながら10億超の顧客データを AI Ready にするデータ基盤設計
baseballyama
1
310
Featured
See All Featured
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Making the Leap to Tech Lead
cromwellryan
135
10k
Optimising Largest Contentful Paint
csswizardry
37
4k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
Building Flexible Design Systems
yeseniaperezcruz
330
41k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Git: the NoSQL Database
bkeepers
PRO
433
67k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Paper Plane
katiecoart
PRO
5
54k
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