Java Generics Flashcards
What is another way or term to understand generics?
It is a parameterized type. Basically it is a way to add a type to a type. It can also add a specific type to it or have a placeholder or parameter to designate a type later, this is a way to reuse code.
What is one big benefit of generics?
One of the keys in software development is to spot a bug quickly because it is cheaper to fix the bug early than it is later.
When do you designate the type in the generic parameter?
when creating the object it would be when you identify the type parameter of the generic. Need to add the generic parameters to the class and then designate them when creating the object.
what is extends in generics?
It is a way to specify more of the generic and show how it can accept a base class or any class that is extended from the parent class. The generic has to be a class that is derived from the bounded type parameter. Extends means it can accept any parent or child of that class
Can you have multiple levels of generics?
Yes can have multiple levels of generics.
What is one advantage of generics?
It will eliminate the type casting statement and it will improve the program’s performance
What is the advantage of the object class?
It can contain anytime of data
Object class
Object class is the parent class for every class. If is on the left side of the literal it is the parent class.
What is the basic syntax to represent a generic?
this will represent the to be determined type.
What is the typical use of the toString() method?
It will be overridded and then used to test the values of the properties
What are the type parameters as part of generics?
Type Parameters
The type parameters naming conventions is important!
The naming conventions are as follows:
T - Type E - Element K - Key N - Number V - Value
What is the Super of generics?
it restricts the extended type that is acceptable to be the selected type and the parents and not all the children.