Generics Flashcards
What is the purpose of generics in Java?
To enable generic algorithms to be written, and types to be defined at a later time.
Which OOP principle does generics enable?
Polymorphism.
How does generics enable safer programs?
Because types are checked at compile time rather than run time.
What are 2 main advantages of Generics?
- Reduces the need for type casting.
- Enables compile time checking of java types.
What is the difference between compile time and run time errors?
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.
What does it mean that generics are non reifiable?
They are not all completely available at run time due to type erasure.
Define Heap Pollution…
A situation in which a variable of a parameterised type refers to a variable of the wrong type, thus causing an unchecked warning.