/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.lang.reflect.*;
abstract class Foo<T> {
private final Class<T> clazz;
public Foo(List<T> list) {
this.clazz = (Class<T>) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
public Class<T> getClazz() {
return clazz;
}
}
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
Foo<Integer> x = new Foo<Integer>(new ArrayList<Integer>()){};
System.
out.
printf("<T> is %s\n", x.
getClazz()); Foo<String> y = new Foo<String>(new ArrayList<String>()){};
System.
out.
printf("<T> is %s\n", y.
getClazz()); // Erro em runtime, <T> é genérico
// criaVersaoGenerica();
}
public static <K> void criaVersaoGenerica() {
Foo<K> k = new Foo<K>(new ArrayList<K>()){};
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLmxhbmcucmVmbGVjdC4qOwoKYWJzdHJhY3QgY2xhc3MgRm9vPFQ+IHsKICAgIHByaXZhdGUgZmluYWwgQ2xhc3M8VD4gY2xheno7CgogICAgcHVibGljIEZvbyhMaXN0PFQ+IGxpc3QpIHsKICAgICAgICB0aGlzLmNsYXp6ID0gKENsYXNzPFQ+KSAoKFBhcmFtZXRlcml6ZWRUeXBlKSBnZXRDbGFzcygpCiAgICAgICAgICAgICAgICAuZ2V0R2VuZXJpY1N1cGVyY2xhc3MoKSkuZ2V0QWN0dWFsVHlwZUFyZ3VtZW50cygpWzBdOwogICAgfQogICAgCiAgICBwdWJsaWMgQ2xhc3M8VD4gZ2V0Q2xhenooKSB7CiAgICAJcmV0dXJuIGNsYXp6OwogICAgfQp9CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsY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