--- In jug-indonesia@yahoogroups.com, Gardiary Jantan <[EMAIL PROTECTED]> wrote: > > Ok, bisa cukup diterima jawabannya :) > > Tp untuk skenario pertama gimana? > public @interface AnAnnotation { > String nama(); > String alamat(); > int umur() default 0; > } > > trus ini: > @AnAnnotation( > nama = "Gue", > alamat = "Jakarta", > umur = 30 ) > public static void aMethod() > { > ... > } > > Gunanya itu annotation buat method itu apa? >
Udah baca reply-reply selanjutnya belom ? Masih kurang ? Hehe... Yang ngerti gunanya ya yang pake kelas itu. Lets get started with real example : public @interface Process { String name(); } public class ProcessImplementation { public void doSomeOtherProcess() { // blabla... } @Process(name="myprocess") public void doSomeProcess() { // real process... } } public class Client { ProcessImplementation p = new ProcessImplementation(); Method[] methods = p.getDeclaredMethods(); for (Method m : methods) { //iterate all methods Annotation ann = m.getAnnotation(Process); // find annotated method if (ann != null) { m.invoke(); // if annotation found, invoke the method } } } Jelas ? Atau tambah puyeng ? hehehehe... Sori kalo kodenya mistyped, nulisnya di notepad, lagi pake komputer orang :P Hendra.