Advertisement
Guest User

Untitled

a guest
May 26th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. package de.tdlabs.training.hacks;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Collection;
  5.  
  6. /**
  7. * Created by tom on 26.05.16.
  8. */
  9. public class GenericReflectionExample {
  10.  
  11. public static void main(String[] args) {
  12.  
  13. System.out.println(wrap(Arrays.<String>asList("a", "b", "c")).getType());
  14. System.out.println(wrap(Arrays.<Integer>asList(1, 2, 3)).getType());
  15. }
  16.  
  17. static <T> Foo wrap(Collection<T> col, T... args) {
  18. return new Foo(args.getClass().getComponentType());
  19. }
  20.  
  21. static class Foo {
  22. private final Class<?> type;
  23.  
  24. public Foo(Class<?> type) {
  25. this.type = type;
  26. }
  27.  
  28. public Class<?> getType() {
  29. return type;
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement