Java Generics Flashcards

1
Q

What is another way or term to understand generics?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is one big benefit of generics?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When do you designate the type in the generic parameter?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is extends in generics?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can you have multiple levels of generics?

A

Yes can have multiple levels of generics.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is one advantage of generics?

A

It will eliminate the type casting statement and it will improve the program’s performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the advantage of the object class?

A

It can contain anytime of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Object class

A

Object class is the parent class for every class. If is on the left side of the literal it is the parent class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the basic syntax to represent a generic?

A

this will represent the to be determined type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the typical use of the toString() method?

A

It will be overridded and then used to test the values of the properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the type parameters as part of generics?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the Super of generics?

A

it restricts the extended type that is acceptable to be the selected type and the parents and not all the children.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly