Part of the code that I'm trying to understand as a beginner java student is below:
public class StandardGA<T extends Chromosome> extends GeneticAlgorithm<T> {
private static final long serialVersionUID = 5043503777821916152L;
private final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(StandardGA.class);
/**
* Constructor
*
* @param factory a {@link org.evosuite.ga.ChromosomeFactory} object.
*/
public StandardGA(ChromosomeFactory<T> factory) {
super(factory);
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected void evolve() {
List<T> newGeneration = new ArrayList<T>();
// Elitism
newGeneration.addAll(elitism());
// new_generation.size() < population_size
while (!isNextPopulationFull(newGeneration)) {
T parent1 = selectionFunction.select(population);
T parent2 = selectionFunction.select(population);
T offspring1 = (T)parent1.clone();
T offspring2 = (T)parent2.clone();
I'm unsure how to search for the answer for what I don't understand as I'm unsure what to call it when I search on the web for answers. If you look at this part of the code
public class StandardGA<T extends Chromosome> extends GeneticAlgorithm<T> {
There is <T extends Chromosome>
which has triangular brackets with "T" in front of it. I'm unsure how you can use extends this way, and I think T is a type but also don't understand what it is or where to look for it.
Also what is the meaning of putting next to the class being extended to "Genetic Algorithms". Whats the difference between simply extending Genetic Algorithms
as opposed to "Genetic Algorithms<T>
".
With my limited understanding I assumed this "T" is a type because lower down in the pasted code you can see for example:
T parent1 = selectionFunction.select(population);
Which sets a variable parent1 as the type "T"? Or am I wrong and this part of code is trying to do something else? Thanks in advance for any answers.