Question: 3. (a) Explain what is generic programming in Java. Give an example of a generic Java class. [20%] (b) Generic programming can be achieved with
3. (a) Explain what is generic programming in Java. Give an example of a generic Java class. [20%]
(b) Generic programming can be achieved with inheritance or with type parameters.
Explain the difference between the two methods. [30%]
(c) Explain why it would be safer to use type parameters rather than inheritance in order to implement a generic class of a list data structure. [30%]
(d) Generics were introduced to the Java language to provide tighter type checks at compile time and to support generic programming. To implement generics, the Java compiler applies type erasure. State one advantage and one disadvantage of type erasure. [20%]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
