Moreover, since Generics eliminates the need to use casting and instanceof function, it makes the code clean and precise. Thus, by showing an error during the compilation, it helps prevent ClassCastException at runtime. If you try to add an element of a different type, Generics will display a compile-time error. Generics lets you specify or define the type of objects that a collection can store. What is the role of Generics in the Collections framework? While arrays do not offer ready-to-use methods (searching, sorting, insertion, etc.) for user requirements, collections always include ready-to-use methods.ģ.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |