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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started