Generics Flashcards

1
Q

What is the purpose of generics in Java?

A

To enable generic algorithms to be written, and types to be defined at a later time.

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

Which OOP principle does generics enable?

A

Polymorphism.

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

How does generics enable safer programs?

A

Because types are checked at compile time rather than run time.

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

What are 2 main advantages of Generics?

A
  • Reduces the need for type casting.
  • Enables compile time checking of java types.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between compile time and run time errors?

A

Compile time usually refers to semantic and syntactical errors. Run-time usually is due to code breakage. Thus, run time is more severe and costly.

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

What does it mean that generics are non reifiable?

A

They are not all completely available at run time due to type erasure.

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

Define Heap Pollution…

A

A situation in which a variable of a parameterised type refers to a variable of the wrong type, thus causing an unchecked warning.

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