Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.tdlabs.training.hacks;
- import java.util.Arrays;
- import java.util.Collection;
- /**
- * Created by tom on 26.05.16.
- */
- public class GenericReflectionExample {
- public static void main(String[] args) {
- System.out.println(wrap(Arrays.<String>asList("a", "b", "c")).getType());
- System.out.println(wrap(Arrays.<Integer>asList(1, 2, 3)).getType());
- }
- static <T> Foo wrap(Collection<T> col, T... args) {
- return new Foo(args.getClass().getComponentType());
- }
- static class Foo {
- private final Class<?> type;
- public Foo(Class<?> type) {
- this.type = type;
- }
- public Class<?> getType() {
- return type;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement