InterviewSolution
| 1. |
What Are Advantages Of Using Generics? |
|
Answer» Advantage of JAVA Generics: There are mainly 3 advantages of generics. They are as follows: TYPE-safety : We can hold only a single type of OBJECTS in generics. It doesn’t allow to store other objects. Type casting is not required: There is no need to typecast the object. Before Generics, we need to type cast. List list = new ArrayList(); Compile-Time Checking: It is checked at compile time so problem will not occur at runtime. The good programming strategy says it is far better to handle the problem at compile time than runtime. List<String> list = new ArrayList<String>(); Advantage of Java Generics: There are mainly 3 advantages of generics. They are as follows: Type-safety : We can hold only a single type of objects in generics. It doesn’t allow to store other objects. Type casting is not required: There is no need to typecast the object. Before Generics, we need to type cast. List list = new ArrayList(); Compile-Time Checking: It is checked at compile time so problem will not occur at runtime. The good programming strategy says it is far better to handle the problem at compile time than runtime. List<String> list = new ArrayList<String>(); |
|