Is there way to pass a Class
variable when instanciating a new template class named TemplateClass
or is it absolutely a non-sens ?
Example of something i would like to do but that do not compile:
final List<TemplateClass> fields = new ArrayList<>();
public void loadDataFields() {
for(Field x : ClassA.class.getDeclaredFields()) {
fields.add(new TemplateClass<x.getClass()>());
}
}
Here is the TemplateClass
:
public class TemplateClass<T extends Comparable> {
int count;
T min;
T max;
}
In short - No.
There is no way it instantiates a template with dynamic class in runtime. That is because templates are evaluated at build time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With