You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenericsLost3.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import java.util.*;
  2. import java.lang.reflect.*;
  3. aspect Foo {
  4. // return type
  5. public List<String> Goo.getStrings() {
  6. return null;
  7. }
  8. // parameters
  9. public void Goo.putStrings(List<String> ls, List<Integer> lls) {
  10. }
  11. // type variables
  12. public <T extends Number> List<T> Goo.numerics(T t) {
  13. return null;
  14. }
  15. // type variables 2
  16. public <T extends List<String>> List<T> Goo.nightmare(T t) {
  17. return null;
  18. }
  19. // type variables 3
  20. public <T extends List<Q>,Q extends Number> List<T> Goo.holyCow(Q t) {
  21. return null;
  22. }
  23. }
  24. class Goo {
  25. }
  26. public class GenericsLost3 {
  27. public static void main(String[]argv) throws Exception {
  28. Method m = Goo.class.getDeclaredMethod("getStrings");
  29. Type t = m.getGenericReturnType();
  30. if (!t.toString().equals("java.util.List<java.lang.String>"))
  31. throw new RuntimeException("Incorrect signature1. Signature is "+t);
  32. m = Goo.class.getDeclaredMethod("putStrings",new Class[]{List.class,List.class});
  33. Type[] ps = m.getGenericParameterTypes();
  34. if (!ps[0].toString().equals("java.util.List<java.lang.String>"))
  35. throw new RuntimeException("Incorrect signature2. Signature is "+t);
  36. if (!ps[1].toString().equals("java.util.List<java.lang.Integer>"))
  37. throw new RuntimeException("Incorrect signature3. Signature is "+t);
  38. m = Goo.class.getDeclaredMethod("numerics", new Class[]{Number.class});
  39. t = m.getGenericReturnType();
  40. if (!t.toString().equals("java.util.List<T>"))
  41. throw new RuntimeException("Incorrect signature4. Signature is "+t);
  42. t = m.getGenericParameterTypes()[0];
  43. if (!t.toString().equals("T"))
  44. throw new RuntimeException("Incorrect signature5. Signature is "+t);
  45. m = Goo.class.getDeclaredMethod("nightmare", new Class[]{List.class});
  46. t = m.getGenericReturnType();
  47. if (!t.toString().equals("java.util.List<T>"))
  48. throw new RuntimeException("Incorrect signature4. Signature is "+t);
  49. t = m.getGenericParameterTypes()[0];
  50. if (!t.toString().equals("T"))
  51. throw new RuntimeException("Incorrect signature5. Signature is "+t);
  52. m = Goo.class.getDeclaredMethod("holyCow", new Class[]{Number.class});
  53. t = m.getGenericReturnType();
  54. if (!t.toString().equals("java.util.List<T>"))
  55. throw new RuntimeException("Incorrect signature4. Signature is "+t);
  56. t = m.getGenericParameterTypes()[0];
  57. if (!t.toString().equals("Q"))
  58. throw new RuntimeException("Incorrect signature5. Signature is "+t);
  59. }
  60. }