Advertisement
Guest User

Untitled

a guest
Sep 12th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package com.jlectra;
  2.  
  3.  
  4. import java.lang.annotation.Annotation;
  5. import java.lang.annotation.Retention;
  6. import java.lang.annotation.RetentionPolicy;
  7. import java.lang.reflect.Method;
  8. import java.util.concurrent.Callable;
  9.  
  10. /**
  11.  * Hello world!
  12.  *
  13.  */
  14. public class App
  15. {
  16.     @Retention(RetentionPolicy.RUNTIME)
  17.     public static @interface Annot {}
  18.  
  19.     public static interface MyCallable extends Callable<Thread>{}
  20.  
  21.     public static abstract class Foo<T extends Runnable, RT extends Callable<T>> {
  22.         private RT obj;
  23.  
  24.         protected void setObj(RT obj) {
  25.             this.obj = obj;
  26.         }
  27.     }
  28.  
  29.     public static class FooBar extends Foo<Thread, MyCallable> {
  30.         @Override
  31.         @Annot
  32.         public void setObj(MyCallable obj) {
  33.             super.setObj(obj);
  34.         }
  35.     }
  36.  
  37.     public static void main( String[] args ) throws Exception
  38.     {
  39.         FooBar fooBar = new FooBar();
  40.  
  41.         for(Method method : FooBar.class.getMethods()) {
  42.             for(Class clazz : method.getParameterTypes()) {
  43.                 StringBuilder anns = new StringBuilder("[");
  44.  
  45.                 for(Annotation ann : method.getAnnotations()) {
  46.                     anns.append(ann.annotationType().getName()).append(",");
  47.                 }
  48.  
  49.                 anns.append("]");
  50.  
  51.                 System.out.println(String.format("%s: %s; %s", method.getName(), clazz.getName(), anns.toString()));
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement