SE 2205a (Unit 1-Part 2) Flashcards
Generic Data Types
What is a generic class?
It can be created to generate a family of classes
What is the key benefit of generics?
To enable errors to be detected at compile error rather than at runtime
What do generic methods introduce?
They introduce their own type of parameters
What is a bounded generic type?
A generic type that can be specified as a subtype of another type is a bounded one
What is the first restriction on generics?
Cannot create an instance of a generic type (i.e. new T())
What is the second restriction on generics?
Generic array creation is not allowed (i.e. new T[100])
What is the third restriction on generics?
A generic type parameter of a class is not allowed in a static context
What is the fourth restriction on generics?
Exception classes cannot be generic
What is an ArrayList?
It is a generic class
What does the ArrayList class allow?
Allows object storage, not primitive-type data storage
How is the ArrayList different from an array?
-It automatically expands when a new item is added
-It automatically shrinks when items are removed
What is the default capacity of an ArrayList?
10 items
What are the three ways of printing items from an ArrayList?
-for loop
-enhanced for loop
-the toString()