Information Technology Reference
In-Depth Information
Generic Classes
Now that you've seen a generic class, let's look at generic classes in more detail and see how
they are created and used.
When you are creating and using your own regular, non-generic classes, there are two
steps in the process: declaring the class and creating instances of the class. But generic classes
are templates for classes, not actual classes—so you must first construct actual class types from
them. You can then create references and instances from these constructed class types.
Figure 19-3 illustrates the process at a high level. If it's not all completely clear yet, don't
worry—each part will be covered in the sections that follow.
1.
Declare a class, using placeholders for some of the types.
2.
Provide actual types to substitute in for the placeholders. This gives you an actual class
definition, with all the “blanks” filled in.
3.
Create instances from the “filled-in” class definition.
Figure 19-3. Creating instances from a generic type
Search WWH ::




Custom Search