In the following class I want to assign the clazz
attribute to the class type by inferring it from the list entered in the constructor.
class Foo<T> {
private Class<T> clazz;
Foo(List<T> list) {
//this.clazz = tipo da classe inferido a partir da lista
}
...
}
My first attempt was to use the method list.getClass()
which was wrong because the value returned by the method was java.util.ArrayList
.
How to infer the type of an informed bean in an ArrayList? Is it possible to make this type of inference from the parameter, as in the example? If so, what would it be like? If not, what are the possibilities, ie how to adjust this class so as to assign the correct value to the attribute clazz
?