View Need For Generic Code In Java
Background. If we already know that our list only holds string data then we need not to typecast it every time. Generics are a facility of generic programming that were added to the java programming language in 2004 within version j2se 5.0.
Generic methods are methods that introduce their own type parameters. Sometimes, it can be applied to most abstract groups of data structures based on the contract the concrete implementations satisfy. The collection framework in java (commonly known as the java collection framework) is comprised of a collection of types that enable you to implement the collection interfaces in the java collections framework include:
Consider the following java code.
The compiler takes care of the type of safety which enables programmers to code easily since they do not have to perform long. A class or interface that operates on parameterized type is called generic. Enabling better code reusability such as implementation of generic algorithms. Generic algorithms need not be always tied to particular data structures or algorithms.
No comments: