That makes your code brittle and debugging hard because the source and the manifestation of error were at two different places.Īnyway, those eras have gone now but the knowledge of this fundamental concept is important while answering Java Generics and Collection interview questions on the real interviews. If you have coded in the pre-generics era then you know that how dreadful those ClassCastException can be which doesn't come when you store elements but comes at the later part of your code when you access those elements. It's natural because Java has been promoting the use of generics and provides compile-time safety with common errors like storing string into an ArrayList of Integer or vice-versa. I haven't written a single line of code where I have used Collections but not Generics. Generics was not part of the original Java release, in fact, it was introduced later at Java 5 release but since then it has become an integral part of Java code. ![]() While the Java Collection framework provides an implementation of some command data structures like List, Set, Array, Hash table, Queue, Stack, PriorityQueue, etc, Generics provides Type safety. They are also used to gauge your experience and depth of your Java knowledge, hence it's imperative for both beginners and experienced Java programmers to prepare this topic well. Hello guys, If you are preparing for Java interviews then you may know that Java Generics and Collections are two of the most important topics, particularly Generics where some of the trickiest Java questions can be asked.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |