WildCard in Class name? What!?

Hi Guys.
I need a bit of help… What the name of this thing Jeff heaton wrote in his classes? I am trying to research for tutorials but i cant find the name of this thing…

 public abstract class Chromosome<GENE_TYPE, GA_TYPE extends GeneticAlgorithm<?>>
		implements Comparable<Chromosome<GENE_TYPE, GA_TYPE>> {
abstract public class GeneticAlgorithm<CHROMOSOME_TYPE extends Chromosome<?, ?>> {

I know that “?” = WildCard
I know that you can do this ArrayList<?> whatever;

But put that in a class name? I never saw that before… Idk what that is supposed to mean…

So my two questions is :
A) What the name of that so i can find tutorials?
B) “?” means any object… right?

Thanks :stuck_out_tongue:

And this is one of the classes im referring to :

https://code.google.com/p/jeffheaton-bookcode/source/browse/trunk/JavaIntroNeuralNetworkEdition2/src/com/heatonresearch/book/introneuralnet/neural/genetic/Chromosome.java?spec=svn41&r=41

Try to search for “Java Generics” tutorials. It’s not very different from ArrayList<?>.

The ArrayList is defined as the following:

[icode]public class ArrayList[/icode], where “E” is a type parameter. If you wanted to restrict E to be a subclass of something, for example in an EntityList (not useful, don’t do this :wink: ), you’d do this:
[icode]public class EntityList[/icode].

You could, instead of “E” also write “ENTITY_TYPE”, like he does in his classes, and it’s a nice idea, but not really the convention, but anyways…

Now if you had something like (again, not really useful) a [icode]public class Container<CONTENT_TYPE>[/icode], and you want a list of containers, but don’t care about what type the container contain, then you’d use the following syntax:
[icode]public class ContainerList<CONTAINER_TYPE extends Container<?>>[/icode].

It’s just getting more and more complicated the more types you abstract away…

In his code, the [icode]GeneticAlgorithm[/icode] simply expects a subclass of [icode]Chromosome[/icode] as Generic Type Parameter, and the Chromosome itself again expects the type (or class) that describes the “Gene” and the [icode]GeneticAlgorithm[/icode] subclass it should be used with, which is kind of a circular dependency, but whatever ;D

Hope this made it at least a little more clear. :slight_smile:

Hey Ty! I will try to research more about Generics.

I simply dont get this part :
“expects a subclass of Chromosome
as Generic Type Parameter,”

Why would a class expect a parameter? Its not in the constructor… I instantiated the classes and they didnt ask anything.

It just means that the “ContainerList” can be one for any type of object (the generic type parameter), but this type must be a subtype of the class “Container”.

i know what it means when its inside a object, like an array list.
But not in a class name.

What do you mean?
“Container”?

 public abstract class Chromosome<GENE_TYPE, GA_TYPE extends GeneticAlgorithm<?>>

This :slight_smile:

Its different than this :
ArrayList<?> ( which i understand)

The top one, i dont.

Easy to understand, hard to explain…
Which partof it?

The whole thing:
This class is and Chromosome, which handles the types of two classes, which you can define on object definition (like String in ArrayList, you know.).
The first class can be any class. The second one only classes that extend ANY “GeneticAlgorithm”.