Generics are compile time markers to provide your compiler typing informations and templates. They don't exist in runtime. You could even ignore generic information in your code:
Factory factory = new IniSecurityManagerFactory("classpath:shiro.ini");
In this case you get a small warning from your IDE (Eclipse) because of unchecked type, but you can supress it with SupressWarning annotation.
@SuppressWarnings("unchecked")
Factory factory = new IniSecurityManagerFactory("classpath:shiro.ini");
Your code will be still compiled without any problem.
For an example you have an Calculate class:
class Calculate<T extends Number> {
private T value;
public T add(T value1, T value2) {
return
}
}
that's a template and you can use your calculation utility with every type extends Number.
Calculate<Integer> calculator = new Calculate<Integer>();
calculator.add(1 , 2);
or a double version;
Calculate<Double> calculator = new Calculate<Double>();
calculator.add(1.2d , 2.3d);
Generics make your code flexible and let you write such templates.
Factory is a idiom in Software Engineering to create objects using these factory classes. I would make a research about Factory Pattern, Dependency Inversion , Holywood Principle.
There are many threads around here about (Abstract) Factory Pattern or even on Wikipedia.