Speaker Deck
Speaker Deck Pro
Sign in
Sign up
for free
†黒魔術† と Annotation と AspectJ
kaiinui
August 23, 2014
Technology
3
1k
†黒魔術† と Annotation と AspectJ
Annotation と AspectJ で楽しい黒魔術 (▰╹◡╹▰)
kaiinui
August 23, 2014
Tweet
Share
More Decks by kaiinui
See All by kaiinui
kaiinui
1
320
kaiinui
0
370
Other Decks in Technology
See All in Technology
humank
0
210
tzkoba
0
380
comucal
PRO
0
410
am7cinnamon
2
2.6k
jakalada
1
260
ishiayaya
PRO
0
320
ytaka23
0
420
hacker2202
0
750
kyonmm
1
1.9k
pinboro
1
1.4k
kentaro
1
310
kanaugust
PRO
0
130
Featured
See All Featured
zenorocha
297
39k
cassininazir
347
20k
philhawksworth
190
17k
jnunemaker
PRO
40
4.5k
davidbonilla
69
3.5k
cherdarchuk
71
260k
hatefulcrawdad
257
17k
imathis
478
150k
smashingmag
229
18k
schacon
145
6.6k
moore
125
21k
michaelherold
225
8.4k
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 をまず使おう (▰╹◡╹▰) 最後に