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
†黒魔術† と Annotation と AspectJ
Search
kaiinui
August 23, 2014
Technology
3
1.2k
†黒魔術† と Annotation と AspectJ
Annotation と AspectJ で楽しい黒魔術 (▰╹◡╹▰)
kaiinui
August 23, 2014
Tweet
Share
More Decks by kaiinui
See All by kaiinui
Black Magic in Java
kaiinui
1
530
API開発自動化と量産
kaiinui
0
430
Other Decks in Technology
See All in Technology
Cloud Native PG 使ってみて気づいたことと最新機能の紹介 - 第52回PostgreSQLアンカンファレンス
seinoyu
2
250
ウォンテッドリーにおける Platform Engineering
bgpat
0
160
FinOps_Demo
tkhresk
0
110
PostgreSQL Unconference #52 pg_tde
nori_shinoda
1
250
DevinはクラウドエンジニアAIになれるのか!? 実践的なガードレール設計/devin-can-become-a-cloud-engineer-ai-practical-guardrail-design
tomoki10
3
1.5k
SREが実現する開発者体験の革新
sansantech
PRO
0
110
OPENLOGI Company Profile for engineer
hr01
1
23k
Proxmox VE超入門 〜 無料で作れるご自宅仮想化プラットフォームブックマークする
devops_vtj
0
230
職種に名前が付く、ということ/The fact that a job title has a name
bitkey
1
270
SSH公開鍵認証による接続 / Connecting with SSH Public Key Authentication
kaityo256
PRO
2
250
Startups On Rails 2025 @ Tropical on Rails
irinanazarova
0
160
Enterprise AI in 2025?
pamelafox
0
120
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
Facilitating Awesome Meetings
lara
53
6.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
30k
Designing for humans not robots
tammielis
251
25k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
118
51k
The Cost Of JavaScript in 2023
addyosmani
48
7.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
BBQ
matthewcrist
88
9.6k
Transcript
†黒魔術† @_kaiinui
=
結論から? (▰╹◡╹▰)
@PotatoTip をつけるだけでトースト
Java の黒魔術: Annotation
Java の黒魔術: Annotation どうみても黒魔術
Java の黒魔術: Annotation Annotation as a code?
良さ? ・宣言的さ ・コードと「宣言」を分離出来る ・コードが短くなったり ・ミスを防止したり(@Nullable)
・ButterKnife の @InjectView ・Support Annotation の @NonNull ・AndroidAnnotations の @UiThread
・Rails の has_many 「する」と「である」を分ける
良い例: ButterKnife の @InjectView
する textView = (TextView) findViewById(R.id.text); である @InjectView(R.id.text) textView;
する runOnUiThread(new Runnable {...}); である @UiThread public void showToast() {..};
さて
Bring your own Annotation!
ツール • AspectJ • java.lang.annotation
初級編 Annotation を普通に使う(AspectJ じゃない)
1. Annotation をつくる(カンタン)
2. 黒魔術
3. 出来た
4. 完成 BananaKnife
中級編 AspectJ でアスペクトを織り込む
1. Annotation をつくる(カンタン)
2. AspectJ で黒魔術
@PotatoTip をつけるだけでトースト
AspectJ の良い例: Hugo
AspectJ の良い例: Hugo あまりに便利なので iOS 版もつくった kaiinui/KILogInjector
一言で? ・Annotation で @Hoge がついたメソッド、フィー ルド、クラスとかを弄れたりする ・AspectJ で処理をフックしてほげほげ、といった 処理がカンタンに書ける。 (▰╹◡╹▰)
きみだけのさいきょう @Annotation をつくろう!
「モデルと API 辛い」周りの話がしたかった あと自分で作るとかどうでもいいので既にある Annotation をまず使おう (▰╹◡╹▰) 最後に